From 39705b4e98c6d6eea6db9ec998e3ed50c6e3f42d Mon Sep 17 00:00:00 2001 From: quanli Date: Thu, 24 Nov 2022 19:50:18 +0800 Subject: [PATCH] quanli1@huawei.com Signed-off-by: quanli --- .../geolocation_standard/src/main/config.json | 247 ++-- .../js/default/test/GeocoderMTest.test.js | 959 +++++++++++++ .../main/js/default/test/GeocoderTest.test.js | 200 +-- .../js/default/test/GetCountryCode.test.js | 10 +- .../js/default/test/GetCountryCodeM.test.js | 164 +++ .../src/main/js/default/test/List.test.js | 5 +- .../js/default/test/LocationMTest.test.js | 1183 +++++++++++++++++ .../main/js/default/test/LocationTest.test.js | 55 +- .../js/default/test/SystemLocation.test.js | 3 +- 9 files changed, 2602 insertions(+), 224 deletions(-) create mode 100644 location/geolocation_standard/src/main/js/default/test/GeocoderMTest.test.js create mode 100644 location/geolocation_standard/src/main/js/default/test/GetCountryCodeM.test.js create mode 100644 location/geolocation_standard/src/main/js/default/test/LocationMTest.test.js diff --git a/location/geolocation_standard/src/main/config.json b/location/geolocation_standard/src/main/config.json index 41bf2df27..969cc6f31 100644 --- a/location/geolocation_standard/src/main/config.json +++ b/location/geolocation_standard/src/main/config.json @@ -1,120 +1,131 @@ -{ - "app": { - "bundleName": "ohos.acts.location.geolocation.function", - "vendor": "acts", - "version": { - "code": 1000000, - "name": "1.0" - }, - "apiVersion": { - "compatible": 4, - "target": 5, - "releaseType": "Beta1" - } - }, - "deviceConfig": {}, - "module": { - "package": "ohos.acts.location.geolocation.function", - "name": ".MyApplication", - "mainAbility": "ohos.acts.location.geolocation.function.MainAbility", - "deviceType": [ +{ + "app": { + "bundleName": "ohos.acts.location.geolocation.function", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.location.geolocation.function", + "name": ".MyApplication", + "mainAbility": "ohos.acts.location.geolocation.function.MainAbility", + "deviceType": [ "tablet", "default", - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry" - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "visible": true, - "name": "ohos.acts.location.geolocation.function.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:app_name", - "type": "page", - "launchType": "standard" - } - ], - "reqPermissions": [ - { - "name": "ohos.permission.LOCATION", - "reason": "need use ohos.permission.LOCATION", - "usedScene": { - "ability": [ - "ohos.acts.location.geolocation.function.MainAbility" - ], - "when": "inuse" - } - }, - { - "name":"ohos.permission.ACCESS_LOCATION", - "reason":"need use ohos.permission.ACCESS_LOCATION", - "usedScene": { - "ability": [ - "ohos.acts.location.geolocation.function.MainAbility" - ], - "when": "inuse" - } - }, - { - "name":"ohos.permission.LOCATION_IN_BACKGROUND", - "reason":"need use ohos.permission.LOCATION_IN_BACKGROUND", - "usedScene": { - "ability": [ - "ohos.acts.location.geolocation.function.MainAbility" - ], - "when": "inuse" - } - }, - { - "name":"ohos.permission.MANAGE_SECURE_SETTINGS", - "reason":"need use ohos.permission.MANAGE_SECURE_SETTINGS", - "usedScene": { - "ability": [ - "ohos.acts.location.geolocation.function.MainAbility" - ], - "when": "inuse" - } - }, - { - "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", - "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" - }, - { - "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", - "reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } -} + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, + "name": "ohos.acts.location.geolocation.function.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.LOCATION", + "reason": "need use ohos.permission.LOCATION", + "usedScene": { + "ability": [ + "ohos.acts.location.geolocation.function.MainAbility" + ], + "when": "inuse" + } + }, + { + "name":"ohos.permission.ACCESS_LOCATION", + "reason":"need use ohos.permission.ACCESS_LOCATION", + "usedScene": { + "ability": [ + "ohos.acts.location.geolocation.function.MainAbility" + ], + "when": "inuse" + } + }, + { + "name":"ohos.permission.APPROXIMATELY_LOCATION", + "reason":"need use ohos.permission.APPROXIMATELY_LOCATION", + "usedScene": { + "ability": [ + "ohos.acts.location.geolocation.function.MainAbility" + ], + "when": "inuse" + } + }, + { + "name":"ohos.permission.LOCATION_IN_BACKGROUND", + "reason":"need use ohos.permission.LOCATION_IN_BACKGROUND", + "usedScene": { + "ability": [ + "ohos.acts.location.geolocation.function.MainAbility" + ], + "when": "inuse" + } + }, + { + "name":"ohos.permission.MANAGE_SECURE_SETTINGS", + "reason":"need use ohos.permission.MANAGE_SECURE_SETTINGS", + "usedScene": { + "ability": [ + "ohos.acts.location.geolocation.function.MainAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} + diff --git a/location/geolocation_standard/src/main/js/default/test/GeocoderMTest.test.js b/location/geolocation_standard/src/main/js/default/test/GeocoderMTest.test.js new file mode 100644 index 000000000..10f4e05fc --- /dev/null +++ b/location/geolocation_standard/src/main/js/default/test/GeocoderMTest.test.js @@ -0,0 +1,959 @@ +/* + * 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 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 geolocationm.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("=== 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_geo5', function () { + + console.log('#start AccessTokenTests#'); + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + + beforeEach(async function (done) { + console.info('beforeEach case'); + await changedLocationMode(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_1900 + * @tc.name testIsGeoServiceAvailable + * @tc.desc Check whether address resolution and reverse address resolution are supported. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_1900', 0, function () { + let geocoder1 = geolocationm.isGeocoderAvailable(); + console.info('[lbs_js] isGeocoderAvailable result: ' + JSON.stringify(geocoder1)); + expect(true).assertEqual(JSON.stringify(geocoder1) != null); + }); + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2000 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Address Resolution Test. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2000', 0, async function (done) { + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 1, "locale": "zh" }; + let promise = new Promise((resolve, reject) => { + geolocationm.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { + if (err) { + console.info('[lbs_js] getAddressesFromLocation20 callback err is:' + JSON.stringify(err)); + } else { + console.info("[lbs_js] getAddressesFromLocation20 callback data is:" + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + } + resolve(); + }); + }) + await promise.then(done); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2100 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Address Resolution Test. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2100', 0, async function (done) { + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 1 }; + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { + console.info('[lbs_js] getAddressesFromLocation21 promise: ' + JSON.stringify(data)); + console.info('addressUrl: ' + JSON.stringify(data)[0].addressUrl + + JSON.stringify(data)[0].administrativeArea + JSON.stringify(data)[0].countryCode + + JSON.stringify(data)[0].countryName + JSON.stringify(data)[0].descriptions + + JSON.stringify(data)[0].descriptionsSize + data[0].latitude + + JSON.stringify(data)[0].locale + JSON.stringify(data)[0].locality + + JSON.stringify(data)[0].longitude + JSON.stringify(data)[0].phoneNumber + + JSON.stringify(data)[0].placeName + + JSON.stringify(data)[0].postalCode + JSON.stringify(data)[0].premises + + JSON.stringify(data)[0].roadName + JSON.stringify(data)[0].subAdministrativeArea + + JSON.stringify(data)[0].subLocality + JSON.stringify(data)[0].subRoadName + + JSON.stringify(data)[0].isFromMock); + done(); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation21 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2200 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Obtaining Multiple Addresses Using the Address Resolution Function. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2200', 0, async function (done) { + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 5 }; + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { + console.info('[lbs_js] getAddressesFromLocation22 promise:' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + done(); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocation22 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2300 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Input parameter boundary test of the address resolution function + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2300', 0, async function (done) { + let reverseGeocodeRequest1 = { "latitude": 90, "longitude": 121.62771, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { + console.info('[lbs_js] getAddressesFromLocation2301 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2301 promise then error." + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + console.info('[lbs_js] not support now'); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest2 = { "latitude": 90.1, "longitude": 121.62771, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { + console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2302 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest3 = { "latitude": -90, "longitude": 121.62771, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { + console.info('[lbs_js] getAddressesFromLocation2303 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2303 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest4 = { "latitude": -90.1, "longitude": 121.62771, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => { + console.info('[lbs_js] getAddressesFromLocation2304 promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2304 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2400 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Input parameter boundary test of the address resolution function + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2400', 0, async function (done) { + let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { + console.info('[lbs_js] getAddressesFromLocation2401 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2401 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest1 = { "latitude": 31.265496, "longitude": -180.1, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { + console.info('[lbs_js] getAddressesFromLocation2402 promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2402 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest2 = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { + console.info('[lbs_js] getAddressesFromLocation2403 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2403 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest3 = { "latitude": 31.265496, "longitude": 180.1, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { + console.info('[lbs_js] getAddressesFromLocation2404 promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation2404 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); + }) + + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2500 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Reverse address resolution test. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2500', 0, async function (done) { + let geocodeRequest = { + "description": "上海市浦东新区金穗路1800号", + "maxItems": 1, + "locale": "zh", + "minLatitude": "", + "minLongitude": "", + "maxLatitude": "", + "maxLongitude": "" + }; + try { + geolocationm.getAddressesFromLocationName(geocodeRequest, (err, data) => { + if (err) { + switch (err) { + case 100: + console.info("NOT_SUPPORTED: " + JSON.stringify(err)); + break; + case 101: + console.info("INPUT_PARAMS_ERROR: " + JSON.stringify(err)); + break; + case 102: + console.info("REVERSE_GEOCODE_ERROR: " + JSON.stringify(err)); + break; + case 103: + console.info("GEOCODE_ERROR: " + JSON.stringify(err)); + break; + case 104: + console.info("LOCATOR_ERROR: " + JSON.stringify(err)); + break; + case 105: + console.info("LOCATION_SWITCH_ERROR: " + JSON.stringify(err)); + break; + case 106: + console.info("LAST_KNOWN_LOCATION_ERROR: " + JSON.stringify(err)); + break; + case 107: + console.info("LOCATION_REQUEST_TIMEOUT_ERROR: " + JSON.stringify(err)); + break; + case 108: + console.info("QUERY_COUNTRY_CODE_ERROR: " + JSON.stringify(err)); + break; + default: + console.info('getAddressesFromLocationName callback err: ' + JSON.stringify(err)); + } + } else { + console.info("[lbs_js] getAddressesFromLocationName08 callback data is: " + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + } + done(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName08 message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2600 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Reverse address resolution test. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2600', 0, async function (done) { + let geocodeRequest = { "description": "上海市浦东新区金穗路1800号", "maxItems": 1 }; + await geolocationm.getAddressesFromLocationName(geocodeRequest).then((result) => { + console.info("[lbs_js] getAddressesFromLocation09 callback data is:" + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName09 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2700 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Obtaining Multiple Locations Using the Reverse Address Resolution Function. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2700', 0, async function (done) { + let geocodeRequest = { "description": "上海市浦东新区金穗路1800号", "maxItems": 5 }; + await geolocationm.getAddressesFromLocationName(geocodeRequest).then((result) => { + console.info("[lbs_js] getAddressesFromLocation10 promise data is:" + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName10 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2800 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid parameter input test for the reverse address resolution function. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2800', 0, async function (done) { + try { + let geocodeRequest = { "description": "", "maxItems": 1 }; + await geolocationm.getAddressesFromLocationName(geocodeRequest).then((result) => { + console.info("[lbs_js] getAddressesFromLocation111 promise data is:" + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName111 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName111 message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest1 = { "description": null, "maxItems": 1 }; + try { + await geolocationm.getAddressesFromLocationName(geocodeRequest1).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName112 promise data is:" + JSON.stringify(result)); + expect(result.length == 0).assertTrue(); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName112 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName112 message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_2900 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Test the reverse address resolution function in the specified range.. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_2900', 0, async function (done) { + let geocodeRequest = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; + await geolocationm.getAddressesFromLocationName(geocodeRequest).then((result) => { + console.info("[lbs_js] getAddressesFromLocation29 promise data is:" + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName29 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_3000 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid input parameter test for the reverse address resolution function in the specified range + * -Invalid location name. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_3000', 0, async function (done) { + let geocodeRequest = { + "description": "", + "maxItems": 1, + "minLatitude": 331.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; + try { + await geolocationm.getAddressesFromLocationName(geocodeRequest).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName301 promise data is:" + JSON.stringify(result)); + expect(result.length == 0).assertTrue(); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName301 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName301 message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest1 = { + "description": null, + "maxItems": 1, + "minLatitude": 331.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; + try { + await geolocationm.getAddressesFromLocationName(geocodeRequest1).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName302 promise data is:" + JSON.stringify(result)); + expect(result.length == 0).assertTrue(); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName302 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName302 message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_3100 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid input parameter test for the reverse address resolution function in the specified range + * - the address is not in the range. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_3100', 0, async function (done) { + let geocodeRequest = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 40.85, + "minLongitude": 116.35, + "maxLatitude": 40.95, + "maxLongitude": 116.45 + }; + await geolocationm.getAddressesFromLocationName(geocodeRequest).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName31 promise data is:" + JSON.stringify(result)); + expect(result.length >= 0).assertTrue(); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName31 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_3200 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Invalid longitude and latitude entered for the reverse address resolution + * function in the specified range. The longitude and latitude range boundary is inverted.. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_3200', 0, async function (done) { + let geocodeRequest = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.95, + "minLongitude": 116.45, + "maxLatitude": 39.85, + "maxLongitude": 116.35 + }; + await geolocationm.getAddressesFromLocationName(geocodeRequest).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName32 promise data is:" + JSON.stringify(result)); + expect(result.length >= 0).assertTrue(); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName32 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_3300 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Input parameter boundary test for the reverse address resolution function in a specified range. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_3300', 0, async function (done) { + let geocodeRequest1 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": -90, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest1).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise1:" + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise1 then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message1." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest2 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 90, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest2).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise2: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise2 then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message2." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest3 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": -90.1, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest3).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise3: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) == null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise3 then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message3." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest4 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 90.1, + "minLongitude": 121.5782001832, + "maxLatitude": 31.1537977881, + "maxLongitude": 121.8026736943 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest4).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise4: " + JSON.stringify(result)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise4 then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message4." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest5 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": -90, + "maxLongitude": 121.8026736943 + }; + try { + await geolocationm.getAddressesFromLocationName(geocodeRequest5).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise5: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise5 then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message5." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest6 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 90, + "maxLongitude": 121.8026736943 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest6).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise6: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise6 then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message6." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest7 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": -90.1, + "maxLongitude": 121.8026736943 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest7).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise7: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) == null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise7 then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message7." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest8 = { + "description": "上海金穗路1800号", + "maxItems": 1, + "minLatitude": 31.3082812847, + "minLongitude": 121.5782001832, + "maxLatitude": 90.1, + "maxLongitude": 121.8026736943 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest8).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise8: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) == null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName33 promise8 then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName33 message8." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Geo_3400 + * @tc.name TestgetAddressesFromLocation + * @tc.desc Longitude input parameter boundary test for the reverse address resolution function in a specified range + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Geo_3400', 0, async function (done) { + let geocodeRequest1 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": -180, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest1).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise1: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise1 then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message1." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest2 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 180, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest2).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise2: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise2 then error." + JSON.stringify(error)); + expect(error.length != 0).assertTrue(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message2." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest3 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": -180.1, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest3).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise3: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise3 then error." + JSON.stringify(error)); + expect(error.length != 0).assertTrue(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message3." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest4 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 180.1, + "maxLatitude": 39.95, + "maxLongitude": 116.45 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest4).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise4: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise4 then error." + JSON.stringify(error)); + expect(error.length != 0).assertTrue(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message4." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest5 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": -180 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest5).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise5: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise5 then error." + JSON.stringify(error)); + expect(error.length != 0).assertTrue(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message5." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest6 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": 180 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest6).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise6: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise6 then error." + JSON.stringify(error)); + expect(error.length != 0).assertTrue(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message6." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest7 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": -180.1 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest7).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise7: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise7 then error." + JSON.stringify(error)); + expect(error.length != 0).assertTrue(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message7." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let geocodeRequest8 = { + "description": "北京天安门", + "maxItems": 1, + "minLatitude": 39.85, + "minLongitude": 116.35, + "maxLatitude": 39.95, + "maxLongitude": 180.1 + }; + try{ + await geolocationm.getAddressesFromLocationName(geocodeRequest8).then((result) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise8: " + JSON.stringify(result)); + expect(true).assertEqual((JSON.stringify(result)) != null); + }).catch((error) => { + console.info("[lbs_js] getAddressesFromLocationName34 promise8 then error." + JSON.stringify(error)); + expect(error.length != 0).assertTrue(); + }); + }catch(error){ + console.info("[lbs_js] getAddressesFromLocationName34 message8." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); + }) +}) diff --git a/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js b/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js index f36668a79..31dcbae1e 100644 --- a/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js +++ b/location/geolocation_standard/src/main/js/default/test/GeocoderTest.test.js @@ -119,7 +119,7 @@ describe('geolocationTest_geo1', function () { expect(true).assertEqual(JSON.stringify(data) != null); done(); } - done() + done(); }) }); @@ -132,14 +132,18 @@ describe('geolocationTest_geo1', function () { * @tc.level Level 2 */ it('SUB_HSS_LocationSystem_Geo_0200', 0, async function (done) { - await geolocation.isGeoServiceAvailable().then((result) => { - console.info('[lbs_js] isGeoServiceAvailable1 promise result: ' + JSON.stringify(result)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(result) != null); - }).catch((error) => { - console.info("[lbs_js] promise then error." + JSON.stringify(error)); - expect().assertFail(); - }); + try { + await geolocation.isGeoServiceAvailable().then((result) => { + console.info('[lbs_js] isGeoServiceAvailable promise result: ' + JSON.stringify(result)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(result) != null); + }).catch((error) => { + console.info("[lbs_js] promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + } catch (error) { + console.info("[lbs_js] isGeoServiceAvailable error." + JSON.stringify(error)); + } done(); }) @@ -161,7 +165,7 @@ describe('geolocationTest_geo1', function () { console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(data)); expect(true).assertEqual((JSON.stringify(data)) != null); } - resolve() + resolve(); }); }) await promise.then(done) @@ -231,40 +235,63 @@ describe('geolocationTest_geo1', function () { */ it('SUB_HSS_LocationSystem_Geo_0600', 0, async function (done) { let reverseGeocodeRequest1 = { "latitude": 90, "longitude": 121.62771, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) != null); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error) != null); - }); + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { + console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + console.info('[lbs_js] not support now'); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest2 = { "latitude": 90.1, "longitude": 121.62771, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { - console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data)); - expect(data.length).assertEqual(0); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0602 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) != null); - }); + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { + console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0602 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest3 = { "latitude": -90, "longitude": 121.62771, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) != null); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0603 promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error) != null); - }); + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { + console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0603 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + let reverseGeocodeRequest4 = { "latitude": -90.1, "longitude": 121.62771, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data)); - expect(data.length).assertEqual(0); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0604 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) != null); - }); - done() + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => { + console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0604 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); }) /** @@ -277,40 +304,60 @@ describe('geolocationTest_geo1', function () { */ it('SUB_HSS_LocationSystem_Geo_0700', 0, async function (done) { let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) != null); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0701 promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error) != null); - }); + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { + console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0701 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } let reverseGeocodeRequest1 = { "latitude": 31.265496, "longitude": -180.1, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data)); - expect(data.length).assertEqual(0); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0702 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) != null); - }); + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => { + console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0702 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } let reverseGeocodeRequest2 = { "latitude": 31.265496, "longitude": 180, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data)); - expect(true).assertEqual((JSON.stringify(data)) != null); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0703 promise then error." + JSON.stringify(error)); - console.info('[lbs_js] not support now'); - expect(true).assertEqual(JSON.stringify(error) != null); - }); + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => { + console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data)); + expect(true).assertEqual((JSON.stringify(data)) != null); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0703 promise then error." + JSON.stringify(error)); + console.info('[lbs_js] not support now'); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } let reverseGeocodeRequest3 = { "latitude": 31.265496, "longitude": 180.1, "maxItems": 1 }; - await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { - console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data)); - expect(data.length).assertEqual(0); - }).catch(error => { - console.info("[lbs_js] getAddressesFromLocation0704 promise then error." + JSON.stringify(error)); - expect(true).assertEqual((JSON.stringify(error)) != null); - }); - done() + try { + await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => { + console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data)); + expect(data.length).assertEqual(0); + }).catch(error => { + console.info("[lbs_js] getAddressesFromLocation0704 promise then error." + JSON.stringify(error)); + expect(true).assertEqual((JSON.stringify(error)) != null); + }); + } catch (error) { + console.info("[lbs_js] getAddressesFromLocation message." + JSON.stringify(error.message)); + expect(true).assertEqual((JSON.stringify(error.message)) != null); + } + done(); }) /** @@ -429,7 +476,6 @@ describe('geolocationTest_geo1', function () { */ it('SUB_HSS_LocationSystem_Geo_1100', 0, async function (done) { try { - let geocodeRequest = { "description": "", "maxItems": 1 }; await geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result)); @@ -566,7 +612,7 @@ describe('geolocationTest_geo1', function () { console.info('[lbs_js] not support now'); expect(true).assertEqual(JSON.stringify(error) != null); }); - done() + done(); }) /** @@ -595,7 +641,7 @@ describe('geolocationTest_geo1', function () { console.info('[lbs_js] not support now'); expect(true).assertEqual(JSON.stringify(error) != null); }); - done() + done(); }) /** @@ -772,7 +818,7 @@ describe('geolocationTest_geo1', function () { console.info("[lbs_js] getAddressesFromLocationName message." + JSON.stringify(error.message)); expect(true).assertEqual((JSON.stringify(error.message)) != null); } - done() + done(); }) /** @@ -949,3 +995,5 @@ describe('geolocationTest_geo1', function () { }) }) + + diff --git a/location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js b/location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js index ee78ae619..a7fc660b8 100644 --- a/location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js +++ b/location/geolocation_standard/src/main/js/default/test/GetCountryCode.test.js @@ -14,7 +14,6 @@ */ import geolocation from '@ohos.geolocation'; import geolocationm from '@ohos.geoLocationManager'; -import geolocations from '@system.geolocation'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import bundle from '@ohos.bundle' import osaccount from '@ohos.account.osAccount' @@ -120,7 +119,7 @@ describe('geolocationTest_4', function () { * @tc.type Function * @tc.level since 9 */ - it('SUB_HSS_LocationSystem_CountryCode_0200', 0, async function (done) { + it('SUB_HSS_LocationSystem_CountryCode_0200', 0, async function (done) { function getCountryCodeCallback() { return new Promise((resolve, reject) => { geolocationm.getCountryCode((err,data) => { @@ -128,7 +127,7 @@ describe('geolocationTest_4', function () { return console.info("getCountryCode callback err: " + JSON.stringify(err)); } else { console.info("getCountryCode callback success"+ JSON.stringify(data)); - expect(true).assertEqual(data != null); + expect(true).assertEqual(data != null); } resolve(); }) @@ -146,7 +145,7 @@ describe('geolocationTest_4', function () { * @tc.level since 9 */ it('SUB_HSS_LocationSystem_CountryCode_0300', 0, async function (done) { - console.info("[lbs_js]countryCodeChange"); + console.info("[lbs_js] countryCodeChange"); geolocationm.on('countryCodeChange', function (data) { console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) ); }); @@ -165,6 +164,3 @@ describe('geolocationTest_4', function () { }) }) - - - diff --git a/location/geolocation_standard/src/main/js/default/test/GetCountryCodeM.test.js b/location/geolocation_standard/src/main/js/default/test/GetCountryCodeM.test.js new file mode 100644 index 000000000..437c0fd6a --- /dev/null +++ b/location/geolocation_standard/src/main/js/default/test/GetCountryCodeM.test.js @@ -0,0 +1,164 @@ +/* + * 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 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 geolocationm.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'); + } +} + +let CountryCodeType = { + COUNTRY_CODE_FROM_LOCALE : 1, + COUNTRY_CODE_FROM_SIM:2, + COUNTRY_CODE_FROM_LOCATION:3, + COUNTRY_CODE_FROM_NETWORK:4, + } + +describe('geolocationTest_6', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + + beforeEach(async function (done) { + console.info('beforeEach case'); + await changedLocationMode(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_CountryCode_0400 + * @tc.name Test getCountryCode + * @tc.desc Obtaining Country Code Information + * @tc.type Function + * @tc.level since 9 + */ + it('SUB_HSS_LocationSystem_CountryCode_0400', 0, async function (done) { + await geolocationm.getCountryCode().then((result) => { + console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result)); + console.info("[lbs_js] country :" + result.country); + console.info("[lbs_js] type: " + result.type); + expect(true).assertTrue(JSON.stringify(result)==CountryCodeType.COUNTRY_CODE_FROM_LOCALE); + expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_SIM); + expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_LOCATION); + expect(true).assertTrue(JSON.stringify(result)!=CountryCodeType.COUNTRY_CODE_FROM_NETWORK); + }).catch((error) => { + console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_CountryCode_0500 + * @tc.name Test getCountryCode + * @tc.desc Obtaining Country Code Information + * @tc.type Function + * @tc.level since 9 + */ + it('SUB_HSS_LocationSystem_CountryCode_0500', 0, async function (done) { + function getCountryCodeCallback() { + return new Promise((resolve, reject) => { + geolocationm.getCountryCode((err,data) => { + if (err) { + return console.info("[lbs_js] getCountryCode callback err: " + JSON.stringify(err)); + } else { + console.info("[lbs_js] getCountryCode callback success"+ JSON.stringify(data)); + expect(true).assertEqual(data != null); + } + resolve(); + }) + }) + } + await getCountryCodeCallback(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_CountryCode_0600 + * @tc.name getCountryCode_on_off + * @tc.desc The interception country code is changed. + * @tc.type Function + * @tc.level since 9 + */ + it('SUB_HSS_LocationSystem_CountryCode_0600', 0, async function (done) { + console.info("[lbs_js] countryCodeChange"); + geolocationm.on('countryCodeChange', function (data) { + console.info('[lbs_js] countryCodeChange' +JSON.stringify(data) ); + }); + await geolocationm.getCountryCode().then((result) => { + console.info("[lbs_js] getCountryCode promise result: " + JSON.stringify(result)); + expect(true).assertTrue(JSON.stringify(result)!=null); + }).catch((error) => { + console.info("[lbs_js] getCountryCode promise then error." + JSON.stringify(error)); + expect().assertFail(); + }); + geolocationm.off('countryCodeChange', function (data) { + console.info('[lbs_js] countryCodeChange' + JSON.stringify(data)); + done(); + }) + done(); + }) + +}) diff --git a/location/geolocation_standard/src/main/js/default/test/List.test.js b/location/geolocation_standard/src/main/js/default/test/List.test.js index 413e3e2ee..76e277e3c 100644 --- a/location/geolocation_standard/src/main/js/default/test/List.test.js +++ b/location/geolocation_standard/src/main/js/default/test/List.test.js @@ -14,6 +14,9 @@ */ require('./GeocoderTest.test.js') +require('./GeocoderMTest.test.js') require('./GetCountryCode.test.js') -require('./SystemLocation.test.js') +require('./GetCountryCodeM.test.js') require('./LocationTest.test.js') +require('./LocationMTest.test.js') +require('./SystemLocation.test.js') diff --git a/location/geolocation_standard/src/main/js/default/test/LocationMTest.test.js b/location/geolocation_standard/src/main/js/default/test/LocationMTest.test.js new file mode 100644 index 000000000..4e7057d1f --- /dev/null +++ b/location/geolocation_standard/src/main/js/default/test/LocationMTest.test.js @@ -0,0 +1,1183 @@ +/* + * 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 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 geolocationm.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)=>{ + geolocationm.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_geo7', function () { + beforeAll(async function (done) { + console.info('beforeAll case'); + await applyPermission(); + done(); + }) + + beforeEach(function () { + console.info('beforeEach case'); + }) + afterEach(function () { + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocSwitch_0600 + * @tc.name Test requestrequestEnableLocation api + * @tc.desc Enabling the Location Service Function for a Third-Party App - Callback + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocSwitch_0600', 0, function () { + let state = geolocationm.isLocationEnabled(); + console.info('[lbs_js] getLocationSwitchState06 result: ' + JSON.stringify(state)); + expect(JSON.stringify(state)).assertTrue(); + }); + + /** + * @tc.number SUB_HSS_LocationSystem_LocSwitch_0700 + * @tc.name Test locationServiceState api . + * @tc.desc Subscribe to the location service status change. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocSwitch_0700', 0, async function (done) { + console.log('[lbs_js] just for overwriting,locationServiceState test need system api '); + var locationServiceState = (state) => { + console.log('[lbs_js] locationServiceState: state: ' + JSON.stringify(state)); + } + geolocationm.on('locationEnabledChange', locationServiceState); + geolocationm.off('locationEnabledChange', locationServiceState); + expect(true).assertTrue(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_1500 + * @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_SingleLoc_1500', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 10 }; + function getCurrentLocationCallback() { + return new Promise((resolve, reject) => { + geolocationm.getCurrentLocation(currentLocationRequest, (err, result) => { + if (err) { + console.info("[lbs_js] getCurrentLocation15 callback err: " + JSON.stringify(err)); + expect(true).assertEqual(err != null); + console.info('[lbs_js] getCurrentLocationCallback reject after'); + done(); + } else { + console.info("[lbs_js] getCurrentLocation15 callback result:" + JSON.stringify(result)); + expect(true).assertEqual(result != null); + resolve(); + } + }); + }) + } + console.info('[lbs_js] getCurrentLocationCallback start'); + await getCurrentLocationCallback(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_1600 + * @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_SingleLoc_1600', 0, async function (done) { + let currentLocationRequest = { "priority": 0x203, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation16 promise result ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation16 promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_1700 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set the track tracing scenario. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_1700', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x302, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info("[lbs_js] getCurrentLocation callback17, result: " + JSON.stringify(result)); + expect(true).assertEqual(result != null); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation callback17:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_1800 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set a car-sharing scenario. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_1800', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x303, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation18 promise result ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation18 promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_1900 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario and set the life service scenario.. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_1900', 0, async function (done) { + let currentLocationRequest = { "priority": 0x200, "scenario": 0x304, "timeoutMs": 1000, "maxAccuracy": 0 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation19 promise result:' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation19 promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2000 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request in a specified scenario + * and set the scenario with no power consumption. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2000', 0, async function (done) { + let currentLocationRequest1 = { "priority": 0x200, "scenario": 0x305, "timeoutMs": 1000, "maxAccuracy": 10 }; + let currentLocationRequest2 = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocationm.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result201 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err201:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocationm.getCurrentLocation(currentLocationRequest2).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result202 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation_0002 promise err202:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2100 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request with the parameter set to high-precision priority location request. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2100', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation21 promise result ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation21 promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2200 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request with parameters set to fast location and priority location request. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2200', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation22 promise result:' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation22 promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2300 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request with parameters set to low power consumption. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2300', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result23:' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err23:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2400 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request and set the location reporting precision. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2400', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 5 }; + let currentLocationRequest1 = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 2 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result241 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err241:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocationm.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result242 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err242:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2500 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request for specific configuration + * and set the reporting precision of abnormal location. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2500', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 }; + let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": -1 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result251 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err0251:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocationm.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result252 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err252:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2600 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a single location request and set the location timeout interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2600', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 }; + let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result261 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err261:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }) + await geolocationm.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result262 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err262:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_SingleLoc_2700 + * @tc.name Test getCurrentLocation + * @tc.desc Initiate a specified single location request and set the exception location timeout interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_SingleLoc_2700', 0, async function (done) { + let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": 0, "maxAccuracy": 0 }; + let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": -1000, "maxAccuracy": 0 }; + await geolocationm.getCurrentLocation(currentLocationRequest).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result271 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err271:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + }); + await geolocationm.getCurrentLocation(currentLocationRequest1).then((result) => { + console.info('[lbs_js] getCurrentLocation promise result272 ' + JSON.stringify(result)); + }).catch(error => { + console.info('[lbs_js] getCurrentLocation promise err272:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + done(); + }) + + /** + * @tc.number SUB_HSS_SendCommand_0300 + * @tc.name Test sendCommand + * @tc.desc Test sendCommand api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_SendCommand_0300', 0, async function (done) { + let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; + try { + await geolocationm.sendCommand(requestInfo, (err, result) => { + if (err) { + console.info('sendcommand callback err:' + JSON.stringify(err)); + expect(true).assertEqual(JSON.stringify(err) != null); + done(); + } + console.info('sendcommand callback result:' + JSON.stringify(result)); + }); + } catch (error) { + console.info('sendcommand callback err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + } + done(); + }) + + /** + * @tc.number SUB_HSS_SendCommand_0400 + * @tc.name Test sendCommand + * @tc.desc Test sendCommand1 api . + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_SendCommand_0400', 0, async function (done) { + let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; + try { + geolocationm.sendCommand(requestInfo).then((result) => { + console.info('sendCommand promise result:' + result); + done(); + }).catch(error => { + console.info('sendcommand promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + } catch (error) { + console.info('sendcommand promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + } + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_1600 + * @tc.name Test locationChange + * @tc.desc Initiate a request for continuous positioning in a specified scenario and set the navigation scenario. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_1600', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.info('[lbs_js] locationChanger16 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_1700 + * @tc.name Test locationChange + * @tc.desc Initiate a request for continuous positioning in a specified scenario and set a track tracing scenario. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_1700', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x302, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.info('[lbs_js] locationChanger17 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_1800 + * @tc.name Test locationChange + * @tc.desc Initiate a continuous location request in a specified scenario and set a car-sharing scenario. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_1800', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":5, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.info('[lbs_js] locationChanger18 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_1900 + * @tc.name Test locationChange + * @tc.desc Initiate a continuous location request in a specified scenario and set a life service scenario. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_1900', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 0}; + var locationChange = (location) => { + console.info('[lbs_js] locationChanger19 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2000 + * @tc.name Test locationChange + * @tc.desc Initiate a continuous location request in a specified scenario + * and set the scenario with no power consumption. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2000', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x305, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange1 = (location) => { + console.log('[lbs_js] locationChanger201 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange1 !=null); + }; + var locationChange2 = (location) => { + console.log('[lbs_js] locationChanger202 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange2 !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange1); + geolocationm.on('locationChange', requestInfo, locationChange2); + geolocationm.off('locationChange', locationChange1); + geolocationm.off('locationChange', locationChange2); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2100 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request and + * set the parameter to high-precision priority positioning request. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2100', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x201, "scenario":0x300, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.log('[lbs_js] locationChanger21 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2200 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request with the parameter + * set to fast positioning and priority positioning request. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2200', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x203, "scenario":0x300, "timeInterval":5, + "distanceInterval": 5, "maxAccuracy": 10}; + var locationChange = (location) => { + console.log('[lbs_js] locationChanger22 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2300 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request with the parameter + * set to low power consumption type. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2300', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x202, "scenario":0x300, "timeInterval":1, + "distanceInterval": 5, "maxAccuracy": 10} + var locationChange = (location) => { + console.log('[lbs_js] locationChanger23 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2400 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the reporting interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2400', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":3, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('[lbs_js] locationChanger24 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_1100 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the location reporting interval. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2500', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('[lbs_js] locationChanger25 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2600 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the interval for reporting exceptions. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2600', 0, async function (done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('[lbs_js] locationChanger26 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2700 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the interval for reporting abnormal locations. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2700', 0, async function (done) { + enableLocationSwitch(); + let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange1 = (location) => { + console.log('[lbs_js] locationChanger271 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange1 !=null); + }; + var locationChange2 = (location) => { + console.log('[lbs_js] locationChanger282 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange2 !=null); + }; + geolocationm.on('locationChange', requestInfo1, locationChange1); + geolocationm.off('locationChange', locationChange1); + geolocationm.on('locationChange', requestInfo2, locationChange2); + geolocationm.off('locationChange', locationChange2); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2800 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous positioning request and set the positioning reporting precision. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2800', 0, async function (done) { + enableLocationSwitch(); + let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 5}; + let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 2}; + var locationChange1 = (location) => { + console.log('[lbs_js] locationChanger281 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange1 !=null); + }; + var locationChange2 = (location) => { + console.log('[lbs_js] locationChanger282 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange2 !=null); + }; + geolocationm.on('locationChange', requestInfo1, locationChange1); + geolocationm.off('locationChange', locationChange1); + geolocationm.on('locationChange', requestInfo2, locationChange2); + geolocationm.off('locationChange', locationChange2); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LocRequest_2900 + * @tc.name Test locationChange + * @tc.desc Initiate a specified continuous location request and set the reporting precision of abnormal location. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LocRequest_2900', 0, async function (done) { + enableLocationSwitch(); + let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": -1}; + var locationChange1 = (location) => { + console.log('[lbs_js] locationChanger291 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange1 !=null); + }; + var locationChange2 = (location) => { + console.log('[lbs_js] locationChanger292 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange2 !=null); + }; + geolocationm.on('locationChange', requestInfo1, locationChange1); + geolocationm.off('locationChange', locationChange1); + geolocationm.on('locationChange', requestInfo2, locationChange2); + geolocationm.off('locationChange', locationChange2); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_LastLoc_0300 + * @tc.name Test getLastLocation + * @tc.desc Obtain the last location after a single location. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_LastLoc_0300', 0, async function(done) { + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.info('[lbs_js] LastlocationChanger1: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('locationChange', locationChange); + try { + let last =geolocationm.getLastLocation(); + console.info('[lbs_js] getLastLocation latitude: ' + result.latitude + + ' longitude: ' + result.longitude +' altitude: ' + result.altitude + +' accuracy: ' + result.accuracy+' speed: ' + result.speed + + 'timeStamp: ' + result.timeStamp+'direction:' + result.direction+' timeSinceBoot: ' + + result.timeSinceBoot +'additions: ' + result.additions+' additionSize' + result.additionSize + + 'isFromMock' +result.isFromMock); + expect(true).assertEqual(JSON.stringify(last) != null); + } catch (error) { + console.info("[lbs_js] getLastLocation error:"+ error) + } + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Gnss_0300 + * @tc.name Test gnssStatusChange + * @tc.desc Monitoring Satellite Information Reporting + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Gnss_0300', 0, async function (done) { + await changedLocationMode(); + var gnssStatusCb = (satelliteStatusInfo) => { + console.info('[lbs_js] gnssStatusChange1: ' + satelliteStatusInfo); + expect(true).assertEqual(satelliteStatusInfo != null) + console.info('[lbs_js] SatelliteStatusInfo satellitesNumber: ' + data[0].satellitesNumber + + 'satelliteIds' + data[0].satelliteIds +'carrierToNoiseDensitys'+ data[0].carrierToNoiseDensitys + +'altitudes' + data[0].altitudes+' azimuths: ' + data[0].azimuths + + 'carrierFrequencies: ' + data[0].carrierFrequencies); + } + geolocationm.on('satelliteStatusChange', gnssStatusCb); + enableLocationSwitch(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var locationChange = (location) => { + console.log('[lbs_js] gnsslocationChanger3: data: ' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + geolocationm.on('locationChange', requestInfo, locationChange); + geolocationm.off('satelliteStatusChange', gnssStatusCb); + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Gnss_0400 + * @tc.name Test nmeaMessageChange + * @tc.desc Monitoring NMEA Information Reporting + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Gnss_0400', 0, async function (done) { + await changedLocationMode(); + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + var nmeaCb = (str) => { + console.log('[lbs_js] nmeaMessage: ' + str); + } + var locationChange = (location) => { + console.log('[lbs_js] gnsslocationChanger4 data:' + JSON.stringify(location)); + expect(true).assertEqual(locationChange !=null); + }; + try { + geolocationm.on('nmeaMessage', nmeaCb); + } catch (error) { + console.info("nmea on err:" + JSON.stringify(error)); + expect(true).assertEqual(error !=null); + done(); + } + geolocationm.on('locationChange', requestInfo, locationChange); + try { + geolocationm.off('nmeaMessage', nmeaCb); + } catch (error) { + console.info("nmea off err:" + JSON.stringify(error)); + expect(true).assertEqual(error !=null); + } + geolocationm.off('locationChange', locationChange); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_0700 + * @tc.name Test cachedGnssLocationsReporting + * @tc.desc Setting the Gnss Batching Reporting Interval + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_0700', 0, async function (done) { + var cachedLocationsCb1 = (locations) => { + console.log('[lbs_js] cachedGnssLocationsReporting7:locations:' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest1 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false}; + geolocationm.on('cachedGnssLocationsChange', CachedGnssLoactionsRequest1, cachedLocationsCb1); + geolocationm.off('cachedGnssLocationsChange',cachedLocationsCb1); + var cachedLocationsCb2 = (locations) => { + console.log('[lbs_js] cachedGnssLocationsReporting7:locations:' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest2 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false}; + geolocationm.on('cachedGnssLocationsChange', CachedGnssLoactionsRequest2, cachedLocationsCb2); + geolocationm.off('cachedGnssLocationsChange',cachedLocationsCb1); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_0800 + * @tc.name Test cachedGnssLocationsReporting + * @tc.desc Setting the Gnss Batching Cache Queue to Be Reported When the Gnss Batching Cache Queue Is Full + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_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}; + geolocationm.on('cachedGnssLocationsChange', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocationm.off('cachedGnssLocationsChange',cachedLocationsCb); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_0900 + * @tc.name Test getCachedGnssLocationsSize + * @tc.desc Obtains the number of GNSS data records in the batching process. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_0900', 0, async function (done) { + var cachedLocationsCb = (locations) => { + console.log('[lbs_js] cachedGnssLocationsReporting9:locations: ' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocationm.on('cachedGnssLocationsChange', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocationm.off('cachedGnssLocationsChange',cachedLocationsCb); + function getCachedGnssLocationsSizeCallback(){ + return new Promise((resolve, reject)=>{ + geolocationm.getCachedGnssLocationsSize((err, data) => { + if (err) { + console.info('[lbs_js] getCachedGnssLocationsSize callback err is : ' + JSON.stringify(err)); + expect(true).assertTrue(err != null); + }else { + console.info("[lbs_js] getCachedGnssLocationsSize callback data is: " + JSON.stringify(data)); + expect(true).assertTrue(data != null); + } + resolve(); + }); + }) + } + await getCachedGnssLocationsSizeCallback(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_1000 + * @tc.name Test getCachedGnssLocationsSize + * @tc.desc Obtains the number of GNSS data records in the batching process. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_1000', 0, async function (done) { + var cachedLocationsCb = (locations) => { + console.log('[lbs_js] cachedGnssLocationsReporting10:locations:' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocationm.on('cachedGnssLocationsChange', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocationm.off('cachedGnssLocationsChange',cachedLocationsCb); + await geolocationm.getCachedGnssLocationsSize().then( (result) => { + console.info('[lbs_js] getCachedGnssLocationsSiz promise '+ JSON.stringify(result)); + expect(true).assertTrue(result != null); + done(); + }).catch((error) => { + console.info("[lbs_js] promise then error." + JSON.stringify(error)); + expect(true).assertTrue(error != null); + done(); + }); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_1100 + * @tc.name Test flushCachedGnssLocations + * @tc.desc Obtains the GNSS data of the current batching. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_1100', 0, async function (done) { + var cachedLocationsCb = (locations) => { + console.log('[lbs_js] cachedGnssLocationsReporting11:locations:' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocationm.on('cachedGnssLocationsChange', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocationm.off('cachedGnssLocationsChange',cachedLocationsCb); + function flushCachedGnssLocationsCallback(){ + return new Promise((resolve, reject)=>{ + geolocationm.flushCachedGnssLocations((err, data) => { + if (err) { + console.info('[lbs_js] flushCachedGnssLocations callback err is : ' + JSON.stringify(err)); + expect(true).assertTrue(err != null); + }else { + console.info("[lbs_js] flushCachedGnssLocations callback data is: " + JSON.stringify(data)); + expect(true).assertTrue(data); + } + resolve(); + }); + }) + } + await flushCachedGnssLocationsCallback(); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_Batching_1200 + * @tc.name Test flushCachedGnssLocations + * @tc.desc Obtain the GNSS data of the current batching. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_HSS_LocationSystem_Batching_1200', 0, async function (done) { + var cachedLocationsCb = (locations) => { + console.log('[lbs_js] cachedGnssLocationsReporting12:locations:' + JSON.stringify(locations)); + expect(true).assertEqual(locations !=null); + } + var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; + let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, + "distanceInterval": 0, "maxAccuracy": 0}; + geolocationm.on('cachedGnssLocationsChange', CachedGnssLoactionsRequest, cachedLocationsCb); + geolocationm.off('cachedGnssLocationsChange',cachedLocationsCb); + await geolocationm.flushCachedGnssLocations().then( (result) => { + console.info('[lbs_js] flushCachedGnssLocations promise '+ JSON.stringify(result)); + expect(true).assertTrue(result); + done(); + }).catch((error) => { + console.info("[lbs_js] promise then error." + JSON.stringify(error)); + expect(true).assertTrue(error != null); + done(); + }); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_GeoFence_0200 + * @tc.name Test fenceStatusChange + * @tc.desc Gnss fence function test + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_HSS_LocationSystem_GeoFence_0200', 0, async function (done) { + await changedLocationMode(); + let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; + let geofenceRequest = {"priority":0x200, "scenario":0x301, "geofence": geofence}; + setTimeout(async ()=>{ + let want = (wantAgent) => { + console.log('[lbs_js] wantAgent: ' + JSON.stringify(wantAgent)); + }; + geolocationm.on('gnssFenceStatusChange', geofenceRequest, + (want) => { + if(err){ + return console.info("fenceStatusChange2 on callback err:" + err); + } + console.info("[lbs_js] fenceStatusChange2 callback result:" + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + done(); + }); + geolocationm.off('gnssFenceStatusChange',geofenceRequest, + (want) => { + if(err){ + return console.info("fenceStatusChange2 callback err:" + err); + } + console.info("[lbs_js] off fenceStatusChange2 callback result:" + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + }); + },1000); + done(); + }) + + /** + * @tc.number SUB_HSS_LocationSystem_GeoFence_0300 + * @tc.name Test fenceStatusChange + * @tc.desc Test the function of locating the validity period of the fence. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 1 + */ + it('SUB_HSS_LocationSystem_GeoFence_0300', 0, async function (done) { + await changedLocationMode(); + let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; + let geofenceRequest = {"priority":0x203, "scenario":0x301, "geofence": geofence}; + setTimeout(async ()=>{ + let want = (wantAgent) => { + console.log('[lbs_js] wantAgent: ' + JSON.stringify(wantAgent)); + }; + geolocationm.on('gnssFenceStatusChange', geofenceRequest, + (want) => { + if(err){ + return console.info("[lbs_js] fenceStatusChange3 on callback err: " + err); + } + console.info("[lbs_js] fenceStatusChange3 callback result: " + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + done(); + }); + geolocationm.off('gnssFenceStatusChange',geofenceRequest, + (want) => { + if(err){ + return console.info("fenceStatusChange3 callback err:" + err); + } + console.info("[lbs_js] off fenceStatusChange3 callback result:" + JSON.stringify(want)); + expect(true).assertEqual(want !=null); + }); + },1000); + done(); + }) +}) diff --git a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js index 2c95b7303..d9e45af0e 100644 --- a/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js +++ b/location/geolocation_standard/src/main/js/default/test/LocationTest.test.js @@ -127,12 +127,12 @@ describe('geolocationTest_geo3', function () { console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data)); expect(data).assertTrue(); } - done() }) + done(); }); /** - * @tc.number LocSwitch_0400 + * @tc.number SUB_HSS_LocationSystem_LocSwitch_0400 * @tc.name Test requestrequestEnableLocation api. * @tc.desc Enabling the Location Service Function for a Third-Party Application -Promise Mode * @tc.size MEDIUM @@ -164,7 +164,7 @@ describe('geolocationTest_geo3', function () { } geolocation.on('locationServiceState', locationServiceState); geolocation.off('locationServiceState', locationServiceState); - expect(true).assertTrue(); + expect(true).assertTrue(); done(); }) @@ -193,7 +193,7 @@ describe('geolocationTest_geo3', function () { }); }) } - console.info('getCurrentLocationCallback start'); + console.info('getCurrentLocationCallback start'); await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { console.info("getCurrentLocation callback_0003, result: " + JSON.stringify(result)); expect(true).assertEqual(result != null); @@ -493,11 +493,9 @@ describe('geolocationTest_geo3', function () { expect(true).assertEqual(JSON.stringify(error) != null); done(); }) - done() + done(); }) - - /** * @tc.number SUB_HSS_SendCommand_0100 * @tc.name Test sendCommand @@ -508,14 +506,20 @@ describe('geolocationTest_geo3', function () { */ it('SUB_HSS_SendCommand_0100', 0, async function (done) { let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; - await geolocation.sendCommand(requestInfo, (err, result) => { - if (err) { - console.info('sendcommand callback err:' + JSON.stringify(err)); - expect(true).assertEqual(JSON.stringify(err) != null); - done(); - } - console.info('sendcommand callback result:' + JSON.stringify(result)); - }); + try { + await geolocation.sendCommand(requestInfo, (err, result) => { + if (err) { + console.info('sendcommand callback err:' + JSON.stringify(err)); + expect(true).assertEqual(JSON.stringify(err) != null); + done(); + } + console.info('sendcommand callback result:' + JSON.stringify(result)); + }); + } catch (error) { + console.info('sendcommand callback err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + } + done(); }) /** @@ -528,14 +532,21 @@ describe('geolocationTest_geo3', function () { */ it('SUB_HSS_SendCommand_0200', 0, async function (done) { let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; - geolocation.sendCommand(requestInfo).then((result) => { - console.info('sendCommand promise result:' + result); - done(); - }).catch(error => { + try { + geolocation.sendCommand(requestInfo).then((result) => { + console.info('sendCommand promise result:' + result); + done(); + }).catch(error => { + console.info('sendcommand promise err:' + JSON.stringify(error)); + expect(true).assertEqual(JSON.stringify(error) != null); + done(); + }) + } catch (error) { console.info('sendcommand promise err:' + JSON.stringify(error)); expect(true).assertEqual(JSON.stringify(error) != null); - done(); - }) + } + done(); + }) /** @@ -1249,3 +1260,5 @@ describe('geolocationTest_geo3', function () { }) }) + + diff --git a/location/geolocation_standard/src/main/js/default/test/SystemLocation.test.js b/location/geolocation_standard/src/main/js/default/test/SystemLocation.test.js index cb4abac83..0dc9ae329 100644 --- a/location/geolocation_standard/src/main/js/default/test/SystemLocation.test.js +++ b/location/geolocation_standard/src/main/js/default/test/SystemLocation.test.js @@ -146,7 +146,7 @@ describe('geolocationTest_geo2', function () { expect().assertFail(); }, }); - geolocation.unsubscribe(); + geolocations.unsubscribe(); console.info("[lbs_js] unsubscribe called") done(); }) @@ -196,3 +196,4 @@ describe('geolocationTest_geo2', function () { + -- GitLab