1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import geolocation from '@ohos.geolocation'; 17import { LocationEventListener } from '@ohos.geolocation'; 18import abilityAccessCtrl from '@ohos.abilityAccessCtrl' 19import bundle from '@ohos.bundle' 20import osaccount from '@ohos.account.osAccount' 21import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' 22let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 , 23 TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303, 24 DAILY_LIFE_SERVICE : 0x304 ,NO_POWER : 0x305} 25let LocationRequestPriority = {UNSET : 0x200 ,ACCURACY : 0x201 ,LOW_POWER : 0x202 ,FIRST_FIX :0x203} 26 27let LocationPrivacyType = { 28 OTHERS : 0, 29 STARTUP: 1, 30 CORE_LOCATION : 2 31} 32function sleep(ms) { 33 return new Promise(resolve => setTimeout(resolve, ms)); 34} 35 36async function changedLocationMode(){ 37 await geolocation.isLocationEnabled().then(async(result) => { 38 console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result)); 39 if(!result){ 40 await geolocation.requestEnableLocation().then(async(result) => { 41 await sleep(3000); 42 console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result)); 43 }).catch((error) => { 44 console.info("[lbs_js] promise then error." + JSON.stringify(error)); 45 expect().assertFail(); 46 }); 47 } 48 }); 49 await geolocation.isLocationEnabled().then(async(result) => { 50 console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result)); 51 }); 52} 53 54async function enableLocationSwitch(){ 55 function enableLocationSwitchCallback(){ 56 return new Promise((resolve, reject)=>{ 57 geolocation.requestEnableLocation((err, data) => { 58 if (err) { 59 console.info('[lbs_js] requestEnableLocation callback err is : ' + err ); 60 }else { 61 console.info("[lbs_js] requestEnableLocation callback data: " + data); 62 expect(data).assertTrue(); 63 } 64 }); 65 }) 66 } 67 await enableLocationSwitchCallback(); 68 done(); 69 70} 71 72 73async function applyPermission() { 74 let osAccountManager = osaccount.getAccountManager(); 75 console.info("=== getAccountManager finish"); 76 let localId = await osAccountManager.getOsAccountLocalIdFromProcess(); 77 console.info("LocalId is :" + localId); 78 let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId); 79 let atManager = abilityAccessCtrl.createAtManager(); 80 if (atManager != null) { 81 let tokenID = appInfo.accessTokenId; 82 console.info('[permission] case accessTokenID is ' + tokenID); 83 let permissionName1 = 'ohos.permission.LOCATION'; 84 let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND'; 85 await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => { 86 console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); 87 }).catch((err) => { 88 console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); 89 }); 90 await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { 91 console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result)); 92 }).catch((err) => { 93 console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err)); 94 }); 95 } else { 96 console.info('[permission] case apply permission failed, createAtManager failed'); 97 } 98} 99 100export default function geolocationTest_geo3() { 101 102 describe('geolocationTest_geo3', function () { 103 beforeAll(async function (done) { 104 console.info('beforeAll case'); 105 await applyPermission(); 106 done(); 107 }) 108 109 beforeEach(function () { 110 console.info('beforeEach case'); 111 }) 112 afterEach(function () { 113 }) 114 115 116 /** 117 * @tc.number SUB_HSS_LocationSystem_LocSwitch_0300 118 * @tc.name Test requestrequestEnableLocation api 119 * @tc.desc Enabling the Location Service Function for a Third-Party App - Callback 120 * @tc.size MEDIUM 121 * @tc.type Function 122 * @tc.level Level 2 123 */ 124 it('SUB_HSS_LocationSystem_LocSwitch_0300', 0, async function (done) { 125 try { 126 geolocation.isLocationEnabled(async (err, data) => { 127 if (err) { 128 console.info('[lbs_js] getLocationSwitchState callback err is : ' + JSON.stringify(err)); 129 130 } else { 131 console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data)); 132 expect(data).assertTrue(); 133 } 134 }) 135 } catch (error) { 136 console.info("[lbs_js] getLocationSwitchState callback try err." + JSON.stringify(error)); 137 expect(true).assertEqual(JSON.stringify(error) != null); 138 } 139 await sleep(1000); 140 done(); 141 }); 142 143 /** 144 * @tc.number SUB_HSS_LocationSystem_LocSwitch_0400 145 * @tc.name Test requestrequestEnableLocation api. 146 * @tc.desc Enabling the Location Service Function for a Third-Party Application -Promise Mode 147 * @tc.size MEDIUM 148 * @tc.type Function 149 * @tc.level Level 2 150 */ 151 it('SUB_HSS_LocationSystem_LocSwitch_0400', 0, async function (done) { 152 try { 153 await geolocation.isLocationEnabled().then((result1) => { 154 console.info('[lbs_js] getLocationSwitchStateLocSwitch_0004 result: ' + JSON.stringify(result1)); 155 expect(result1).assertTrue(); 156 }).catch((error) => { 157 console.info("[lbs_js] getLocationSwitchStateLocSwitch_0004 err." + JSON.stringify(error)); 158 expect().assertFail(); 159 }); 160 } catch (error) { 161 console.info("[lbs_js] getLocationSwitchState callback try err." + JSON.stringify(error)); 162 expect().assertFail(); 163 } 164 done(); 165 }); 166 167 /** 168 * @tc.number SUB_HSS_LocationSystem_LocSwitch_0500 169 * @tc.name Test locationServiceState api . 170 * @tc.desc Subscribe to the location service status change. 171 * @tc.size MEDIUM 172 * @tc.type Function 173 * @tc.level Level 2 174 */ 175 it('SUB_HSS_LocationSystem_LocSwitch_0500', 0, async function (done) { 176 console.log('just for overwriting,locationServiceState test need system api'); 177 var locationServiceState = (state) => { 178 console.log('locationServiceState: state: ' + JSON.stringify(state)); 179 } 180 try { 181 geolocation.on('locationServiceState', locationServiceState); 182 } catch (error) { 183 console.info("[lbs_js] locationServiceStateOn05 try err." + JSON.stringify(error)); 184 expect(true).assertEqual(JSON.stringify(error) != null); 185 } 186 try { 187 geolocation.off('locationServiceState', locationServiceState); 188 } catch (error) { 189 console.info("[lbs_js] locationServiceStateOff05 try err." + JSON.stringify(error)); 190 expect(true).assertEqual(JSON.stringify(error) != null); 191 } 192 done(); 193 }) 194 195 /** 196 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0100 197 * @tc.name Test getCurrentLocation 198 * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario.. 199 * @tc.size MEDIUM 200 * @tc.type Function 201 * @tc.level Level 2 202 */ 203 it('SUB_HSS_LocationSystem_SingleLoc_0100', 0, async function (done) { 204 let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 0 }; 205 try { 206 geolocation.getCurrentLocation(currentLocationRequest, (err, result) => { 207 if (err) { 208 console.info("[lbs_js] getCurrentLocation callback err: " + JSON.stringify(err)); 209 expect(true).assertEqual(err != null); 210 console.info('[lbs_js] getCurrentLocationCallback reject after') 211 } else { 212 console.info("[lbs_js] getCurrentLocation callback, result: " + JSON.stringify(result)); 213 expect(true).assertEqual(result != null); 214 } 215 }); 216 } catch (error) { 217 console.info("[lbs_js] getCurrentLocation callback try err." + JSON.stringify(error)); 218 expect(true).assertEqual(JSON.stringify(error) != null); 219 } 220 await sleep(1000); 221 done(); 222 }) 223 224 /** 225 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0200 226 * @tc.name Test getCurrentLocation 227 * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario.. 228 * @tc.size MEDIUM 229 * @tc.type Function 230 * @tc.level Level 2 231 */ 232 it('SUB_HSS_LocationSystem_SingleLoc_0200', 0, async function (done) { 233 let currentLocationRequest = { "priority": 0x203, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 0 }; 234 try { 235 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 236 console.info('[lbs_js] getCurrentLocation promise result ' + JSON.stringify(result)); 237 }).catch(error => { 238 console.info('[lbs_js] getCurrentLocation_0002 promise err:' + JSON.stringify(error)); 239 expect(true).assertEqual(JSON.stringify(error) != null); 240 }) 241 } catch (error) { 242 console.info("[lbs_js] getCurrentLocation promise try err." + JSON.stringify(error)); 243 expect(true).assertEqual(JSON.stringify(error) != null); 244 } 245 done(); 246 }) 247 248 /** 249 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0300 250 * @tc.name Test getCurrentLocation 251 * @tc.desc Initiate a single location request in a specified scenario and set the track tracing scenario. 252 * @tc.size MEDIUM 253 * @tc.type Function 254 * @tc.level Level 2 255 */ 256 it('SUB_HSS_LocationSystem_SingleLoc_0300', 0, async function (done) { 257 let currentLocationRequest = { "priority": 0x200, "scenario": 0x302, "timeoutMs": 1000, "maxAccuracy": 10 }; 258 try { 259 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 260 console.info("[lbs_js] getCurrentLocation callback_0003, result: " + JSON.stringify(result)); 261 expect(true).assertEqual(result != null); 262 }).catch(error => { 263 console.info('[lbs_js] getCurrentLocation callback_0003:' + JSON.stringify(error)); 264 expect(true).assertEqual(JSON.stringify(error) != null); 265 }) 266 } catch (error) { 267 console.info("[lbs_js] getCurrentLocation callback03 try err." + JSON.stringify(error)); 268 expect(true).assertEqual(JSON.stringify(error) != null); 269 } 270 done(); 271 }) 272 273 /** 274 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0400 275 * @tc.name Test getCurrentLocation 276 * @tc.desc Initiate a single location request in a specified scenario and set a car-sharing scenario. 277 * @tc.size MEDIUM 278 * @tc.type Function 279 * @tc.level Level 2 280 */ 281 it('SUB_HSS_LocationSystem_SingleLoc_0400', 0, async function (done) { 282 let currentLocationRequest = { "priority": 0x200, "scenario": 0x303, "timeoutMs": 1000, "maxAccuracy": 10 }; 283 try { 284 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 285 console.info('[lbs_js] getCurrentLocation promise result004 ' + JSON.stringify(result)); 286 }).catch(error => { 287 console.info('getCurrentLocation promise err004:' + JSON.stringify(error)); 288 expect(true).assertEqual(JSON.stringify(error) != null); 289 }) 290 } catch (error) { 291 console.info("[lbs_js] getCurrentLocation promise04 try err." + JSON.stringify(error)); 292 expect(true).assertEqual(JSON.stringify(error) != null); 293 } 294 done(); 295 }) 296 297 /** 298 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0500 299 * @tc.name Test getCurrentLocation 300 * @tc.desc Initiate a single location request in a specified scenario and set the life service scenario.. 301 * @tc.size MEDIUM 302 * @tc.type Function 303 * @tc.level Level 2 304 */ 305 it('SUB_HSS_LocationSystem_SingleLoc_0500', 0, async function (done) { 306 let currentLocationRequest = { "priority": 0x200, "scenario": 0x304, "timeoutMs": 1000, "maxAccuracy": 0 }; 307 try { 308 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 309 console.info('[lbs_js] getCurrentLocation promise result005 ' + JSON.stringify(result)); 310 }).catch(error => { 311 console.info('getCurrentLocation promise err005:' + JSON.stringify(error)); 312 expect(true).assertEqual(JSON.stringify(error) != null); 313 }) 314 } catch (error) { 315 console.info("[lbs_js] getCurrentLocation promise05 try err." + JSON.stringify(error)); 316 expect(true).assertEqual(JSON.stringify(error) != null); 317 } 318 done(); 319 }) 320 321 /** 322 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0600 323 * @tc.name Test getCurrentLocation 324 * @tc.desc Initiate a single location request in a specified scenario 325 * and set the scenario with no power consumption. 326 * @tc.size MEDIUM 327 * @tc.type Function 328 * @tc.level Level 2 329 */ 330 it('SUB_HSS_LocationSystem_SingleLoc_0600', 0, async function (done) { 331 let currentLocationRequest1 = { "priority": 0x200, "scenario": 0x305, "timeoutMs": 1000, "maxAccuracy": 10 }; 332 let currentLocationRequest2 = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 10 }; 333 try { 334 await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { 335 console.info('[lbs_js] getCurrentLocation promise result061 ' + JSON.stringify(result)); 336 }).catch(error => { 337 console.info('[lbs_js]getCurrentLocation promise err061:' + JSON.stringify(error)); 338 expect(true).assertEqual(JSON.stringify(error) != null); 339 }) 340 } catch (error) { 341 console.info("[lbs_js] getCurrentLocation promise061 try err." + JSON.stringify(error)); 342 expect(true).assertEqual(JSON.stringify(error) != null); 343 } 344 try { 345 await geolocation.getCurrentLocation(currentLocationRequest2).then((result) => { 346 console.info('[lbs_js] getCurrentLocation promise result062 ' + JSON.stringify(result)); 347 }).catch(error => { 348 console.info('[lbs_js]getCurrentLocation promise err062:' + JSON.stringify(error)); 349 expect(true).assertEqual(JSON.stringify(error) != null); 350 }) 351 } catch (error) { 352 console.info("[lbs_js] getCurrentLocation promise062 try err." + JSON.stringify(error)); 353 expect(true).assertEqual(JSON.stringify(error) != null); 354 } 355 done(); 356 }) 357 358 /** 359 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0700 360 * @tc.name Test getCurrentLocation 361 * @tc.desc Initiate a single location request with the parameter set to high-precision priority location request. 362 * @tc.size MEDIUM 363 * @tc.type Function 364 * @tc.level Level 2 365 */ 366 it('SUB_HSS_LocationSystem_SingleLoc_0700', 0, async function (done) { 367 let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 }; 368 try { 369 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 370 console.info('[lbs_js] getCurrentLocation promise result007 ' + JSON.stringify(result)); 371 }).catch(error => { 372 console.info('getCurrentLocation promise err007:' + JSON.stringify(error)); 373 expect(true).assertEqual(JSON.stringify(error) != null); 374 }) 375 } catch (error) { 376 console.info("[lbs_js] getCurrentLocation promise07 try err." + JSON.stringify(error)); 377 expect(true).assertEqual(JSON.stringify(error) != null); 378 } 379 done(); 380 }) 381 382 /** 383 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0800 384 * @tc.name Test getCurrentLocation 385 * @tc.desc Initiate a single location request with parameters set to fast location and priority location request. 386 * @tc.size MEDIUM 387 * @tc.type Function 388 * @tc.level Level 2 389 */ 390 it('SUB_HSS_LocationSystem_SingleLoc_0800', 0, async function (done) { 391 let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 }; 392 try { 393 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 394 console.info('[lbs_js] getCurrentLocation promise result010 ' + JSON.stringify(result)); 395 }).catch(error => { 396 console.info('getCurrentLocation promise err010:' + JSON.stringify(error)); 397 expect(true).assertEqual(JSON.stringify(error) != null); 398 }) 399 } catch (error) { 400 console.info("[lbs_js] getCurrentLocation promise08 try err." + JSON.stringify(error)); 401 expect(true).assertEqual(JSON.stringify(error) != null); 402 } 403 done(); 404 }) 405 406 /** 407 * @tc.number SUB_HSS_LocationSystem_SingleLoc_0900 408 * @tc.name Test getCurrentLocation 409 * @tc.desc Initiate a single location request with parameters set to low power consumption. 410 * @tc.size MEDIUM 411 * @tc.type Function 412 * @tc.level Level 2 413 */ 414 it('SUB_HSS_LocationSystem_SingleLoc_0900', 0, async function (done) { 415 let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 }; 416 try { 417 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 418 console.info('[lbs_js] getCurrentLocation promise result009 ' + JSON.stringify(result)); 419 }).catch(error => { 420 console.info('getCurrentLocation promise err009:' + JSON.stringify(error)); 421 expect(true).assertEqual(JSON.stringify(error) != null); 422 }) 423 } catch (error) { 424 console.info("[lbs_js] getCurrentLocation promise09 try err." + JSON.stringify(error)); 425 expect(true).assertEqual(JSON.stringify(error) != null); 426 } 427 done(); 428 }) 429 430 /** 431 * @tc.number SUB_HSS_LocationSystem_SingleLoc_1000 432 * @tc.name Test getCurrentLocation 433 * @tc.desc Initiate a single location request and set the location reporting precision. 434 * @tc.size MEDIUM 435 * @tc.type Function 436 * @tc.level Level 2 437 */ 438 it('SUB_HSS_LocationSystem_SingleLoc_1000', 0, async function (done) { 439 let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 5 }; 440 let currentLocationRequest1 = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 2 }; 441 try { 442 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 443 console.info('[lbs_js] getCurrentLocation promise result010 ' + JSON.stringify(result)); 444 }).catch(error => { 445 console.info('getCurrentLocation promise err010:' + JSON.stringify(error)); 446 expect(true).assertEqual(JSON.stringify(error) != null); 447 }) 448 } catch (error) { 449 console.info("[lbs_js] getCurrentLocation promise101 try err." + JSON.stringify(error)); 450 expect(true).assertEqual(JSON.stringify(error) != null); 451 } 452 try { 453 await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { 454 console.info('[lbs_js] getCurrentLocation promise result0102 ' + JSON.stringify(result)); 455 }).catch(error => { 456 console.info('getCurrentLocation promise err0102:' + JSON.stringify(error)); 457 expect(true).assertEqual(JSON.stringify(error) != null); 458 }) 459 } catch (error) { 460 console.info("[lbs_js] getCurrentLocation promise102 try err." + JSON.stringify(error)); 461 expect(true).assertEqual(JSON.stringify(error) != null); 462 } 463 done(); 464 }) 465 466 /** 467 * @tc.number SUB_HSS_LocationSystem_SingleLoc_1100 468 * @tc.name Test getCurrentLocation 469 * @tc.desc Initiate a single location request for specific configuration 470 * and set the reporting precision of abnormal location. 471 * @tc.size MEDIUM 472 * @tc.type Function 473 * @tc.level Level 2 474 */ 475 it('SUB_HSS_LocationSystem_SingleLoc_1100', 0, async function (done) { 476 let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 }; 477 let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": -1 }; 478 try { 479 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 480 console.info('[lbs_js] getCurrentLocation promise result011 ' + JSON.stringify(result)); 481 }).catch(error => { 482 console.info('getCurrentLocation promise err011:' + JSON.stringify(error)); 483 expect(true).assertEqual(JSON.stringify(error) != null); 484 }) 485 } catch (error) { 486 console.info("[lbs_js] getCurrentLocation promise111 try err." + JSON.stringify(error)); 487 expect(true).assertEqual(JSON.stringify(error) != null); 488 } 489 try { 490 await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { 491 console.info('[lbs_js] getCurrentLocation promise result0112 ' + JSON.stringify(result)); 492 }).catch(error => { 493 console.info('getCurrentLocation promise err0112:' + JSON.stringify(error)); 494 expect(true).assertEqual(JSON.stringify(error) != null); 495 }) 496 } catch (error) { 497 console.info("[lbs_js] getCurrentLocation promise112 try err." + JSON.stringify(error)); 498 expect(true).assertEqual(JSON.stringify(error) != null); 499 } 500 done(); 501 }) 502 503 /** 504 * @tc.number SUB_HSS_LocationSystem_SingleLoc_1200 505 * @tc.name Test getCurrentLocation 506 * @tc.desc Initiate a single location request and set the location timeout interval. 507 * @tc.size MEDIUM 508 * @tc.type Function 509 * @tc.level Level 2 510 */ 511 it('SUB_HSS_LocationSystem_SingleLoc_1200', 0, async function (done) { 512 let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 }; 513 let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 }; 514 try { 515 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 516 console.info('[lbs_js] getCurrentLocation promise result012 ' + JSON.stringify(result)); 517 }).catch(error => { 518 console.info('getCurrentLocation promise err012:' + JSON.stringify(error)); 519 expect(true).assertEqual(JSON.stringify(error) != null); 520 }) 521 } catch (error) { 522 console.info("[lbs_js] getCurrentLocation promise121 try err." + JSON.stringify(error)); 523 expect(true).assertEqual(JSON.stringify(error) != null); 524 } 525 try { 526 await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { 527 console.info('[lbs_js] getCurrentLocation promise result0122 ' + JSON.stringify(result)); 528 }).catch(error => { 529 console.info('getCurrentLocation promise err0122:' + JSON.stringify(error)); 530 expect(true).assertEqual(JSON.stringify(error) != null); 531 }) 532 } catch (error) { 533 console.info("[lbs_js] getCurrentLocation promise122 try err." + JSON.stringify(error)); 534 expect(true).assertEqual(JSON.stringify(error) != null); 535 } 536 done(); 537 }) 538 539 /** 540 * @tc.number SUB_HSS_LocationSystem_SingleLoc_1300 541 * @tc.name Test getCurrentLocation 542 * @tc.desc Initiate a specified single location request and set the exception location timeout interval. 543 * @tc.size MEDIUM 544 * @tc.type Function 545 * @tc.level Level 2 546 */ 547 it('SUB_HSS_LocationSystem_SingleLoc_1300', 0, async function (done) { 548 let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": 0, "maxAccuracy": 0 }; 549 let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": -1000, "maxAccuracy": 0 }; 550 try { 551 await geolocation.getCurrentLocation(currentLocationRequest).then((result) => { 552 console.info('[lbs_js] getCurrentLocation promise result131 ' + JSON.stringify(result)); 553 }).catch(error => { 554 console.info('getCurrentLocation promise err131:' + JSON.stringify(error)); 555 expect(true).assertEqual(JSON.stringify(error) != null); 556 }); 557 } catch (error) { 558 console.info("[lbs_js] getCurrentLocation promise131 try err." + JSON.stringify(error)); 559 expect(true).assertEqual(JSON.stringify(error) != null); 560 } 561 try { 562 await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => { 563 console.info('[lbs_js] getCurrentLocation promise result132 ' + JSON.stringify(result)); 564 }).catch(error => { 565 console.info('getCurrentLocation promise err132:' + JSON.stringify(error)); 566 expect(true).assertEqual(JSON.stringify(error) != null); 567 }) 568 } catch (error) { 569 console.info("[lbs_js] getCurrentLocation promise132 try err." + JSON.stringify(error)); 570 expect(true).assertEqual(JSON.stringify(error) != null); 571 } 572 done(); 573 }) 574 575 /** 576 * @tc.number SUB_HSS_SendCommand_0100 577 * @tc.name Test sendCommand 578 * @tc.desc Test sendCommand api . 579 * @tc.size MEDIUM 580 * @tc.type Function 581 * @tc.level Level 2 582 */ 583 it('SUB_HSS_SendCommand_0100', 0, async function (done) { 584 let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; 585 try { 586 await geolocation.sendCommand(requestInfo, (err, result) => { 587 if (err) { 588 console.info('sendcommand callback err:' + JSON.stringify(err)); 589 expect(true).assertEqual(JSON.stringify(err) != null); 590 done(); 591 } 592 console.info('sendcommand callback result:' + JSON.stringify(result)); 593 }); 594 } catch (error) { 595 console.info('sendcommand callback err:' + JSON.stringify(error)); 596 expect(true).assertEqual(JSON.stringify(error) != null); 597 } 598 done(); 599 }) 600 601 /** 602 * @tc.number SUB_HSS_SendCommand_0200 603 * @tc.name Test sendCommand 604 * @tc.desc Test sendCommand1 api . 605 * @tc.size MEDIUM 606 * @tc.type Function 607 * @tc.level Level 2 608 */ 609 it('SUB_HSS_SendCommand_0200', 0, async function (done) { 610 let requestInfo = { 'scenairo': 0x301, 'command': "command_1" }; 611 try { 612 geolocation.sendCommand(requestInfo).then((result) => { 613 console.info('sendCommand promise result:' + result); 614 done(); 615 }).catch(error => { 616 console.info('sendcommand promise err:' + JSON.stringify(error)); 617 expect(true).assertEqual(JSON.stringify(error) != null); 618 done(); 619 }) 620 } catch (error) { 621 console.info('sendcommand promise err:' + JSON.stringify(error)); 622 expect(true).assertEqual(JSON.stringify(error) != null); 623 } 624 done(); 625 626 }) 627 628 /** 629 * @tc.number SUB_HSS_LocationSystem_LocRequest_0100 630 * @tc.name Test locationChange 631 * @tc.desc Initiate a request for continuous positioning in a specified scenario and set the navigation scenario. 632 * @tc.size MEDIUM 633 * @tc.type Function 634 * @tc.level Level 2 635 */ 636 it('SUB_HSS_LocationSystem_LocRequest_0100', 0, async function (done) { 637 enableLocationSwitch(); 638 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, 639 "distanceInterval": 0, "maxAccuracy": 0}; 640 var locationChange = (location) => { 641 console.log('locationChanger: data: ' + JSON.stringify(location)); 642 expect(true).assertEqual(locationChange !=null); 643 }; 644 try { 645 geolocation.on('locationChange', requestInfo, locationChange); 646 } catch (error) { 647 console.info("[lbs_js] locationChangeOn01 try err." + JSON.stringify(error)); 648 expect(true).assertEqual(JSON.stringify(error) != null); 649 } 650 try { 651 geolocation.off('locationChange', locationChange); 652 } catch (error) { 653 console.info("[lbs_js] locationChangeOff01 try err." + JSON.stringify(error)); 654 expect(true).assertEqual(JSON.stringify(error) != null); 655 } 656 done(); 657 }) 658 659 /** 660 * @tc.number SUB_HSS_LocationSystem_LocRequest_0200 661 * @tc.name Test locationChange 662 * @tc.desc Initiate a request for continuous positioning in a specified scenario and set a track tracing scenario. 663 * @tc.size MEDIUM 664 * @tc.type Function 665 * @tc.level Level 2 666 */ 667 it('SUB_HSS_LocationSystem_LocRequest_0200', 0, async function (done) { 668 enableLocationSwitch(); 669 let requestInfo = {"priority":0x200, "scenario":0x302, "timeInterval":1, 670 "distanceInterval": 5, "maxAccuracy": 10}; 671 var locationChange = (location) => { 672 console.log('locationChanger: data: ' + JSON.stringify(location)); 673 expect(true).assertEqual(locationChange !=null); 674 }; 675 try { 676 geolocation.on('locationChange', requestInfo, locationChange); 677 } catch (error) { 678 console.info("[lbs_js] locationChangeOn02 try err." + JSON.stringify(error)); 679 expect(true).assertEqual(JSON.stringify(error) != null); 680 } 681 try { 682 geolocation.off('locationChange', locationChange); 683 } catch (error) { 684 console.info("[lbs_js] locationChangeOff02 try err." + JSON.stringify(error)); 685 expect(true).assertEqual(JSON.stringify(error) != null); 686 } 687 done(); 688 }) 689 690 /** 691 * @tc.number SUB_HSS_LocationSystem_LocRequest_0300 692 * @tc.name Test locationChange 693 * @tc.desc Initiate a continuous location request in a specified scenario and set a car-sharing scenario. 694 * @tc.size MEDIUM 695 * @tc.type Function 696 * @tc.level Level 2 697 */ 698 it('SUB_HSS_LocationSystem_LocRequest_0300', 0, async function (done) { 699 enableLocationSwitch(); 700 let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":5, 701 "distanceInterval": 5, "maxAccuracy": 10}; 702 var locationChange = (location) => { 703 console.log('locationChanger: data: ' + JSON.stringify(location)); 704 expect(true).assertEqual(locationChange !=null); 705 }; 706 try { 707 geolocation.on('locationChange', requestInfo, locationChange); 708 } catch (error) { 709 console.info("[lbs_js] locationChangeOn03 try err." + JSON.stringify(error)); 710 expect(true).assertEqual(JSON.stringify(error) != null); 711 } 712 try { 713 geolocation.off('locationChange', locationChange); 714 } catch (error) { 715 console.info("[lbs_js] locationChangeOff03 try err." + JSON.stringify(error)); 716 expect(true).assertEqual(JSON.stringify(error) != null); 717 } 718 done(); 719 }) 720 721 /** 722 * @tc.number SUB_HSS_LocationSystem_LocRequest_0400 723 * @tc.name Test locationChange 724 * @tc.desc Initiate a continuous location request in a specified scenario and set a life service scenario. 725 * @tc.size MEDIUM 726 * @tc.type Function 727 * @tc.level Level 2 728 */ 729 it('SUB_HSS_LocationSystem_LocRequest_0400', 0, async function (done) { 730 enableLocationSwitch(); 731 let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":1, 732 "distanceInterval": 5, "maxAccuracy": 0}; 733 var locationChange = (location) => { 734 console.log('locationChanger: data: ' + JSON.stringify(location)); 735 expect(true).assertEqual(locationChange !=null); 736 }; 737 try { 738 geolocation.on('locationChange', requestInfo, locationChange); 739 } catch (error) { 740 console.info("[lbs_js] locationChangeOn04 try err." + JSON.stringify(error)); 741 expect(true).assertEqual(JSON.stringify(error) != null); 742 } 743 try { 744 geolocation.off('locationChange', locationChange); 745 } catch (error) { 746 console.info("[lbs_js] locationChangeOff04 try err." + JSON.stringify(error)); 747 expect(true).assertEqual(JSON.stringify(error) != null); 748 } 749 done(); 750 }) 751 752 /** 753 * @tc.number SUB_HSS_LocationSystem_LocRequest_0500 754 * @tc.name Test locationChange 755 * @tc.desc Initiate a continuous location request in a specified scenario 756 * and set the scenario with no power consumption. 757 * @tc.size MEDIUM 758 * @tc.type Function 759 * @tc.level Level 2 760 */ 761 it('SUB_HSS_LocationSystem_LocRequest_0500', 0, async function (done) { 762 enableLocationSwitch(); 763 let requestInfo = {"priority":0x200, "scenario":0x305, "timeInterval":1, 764 "distanceInterval": 5, "maxAccuracy": 10}; 765 var locationChange1 = (location) => { 766 console.log('locationChanger: data: ' + JSON.stringify(location)); 767 expect(true).assertEqual(locationChange1 !=null); 768 }; 769 var locationChange2 = (location) => { 770 console.log('locationChanger: data: ' + JSON.stringify(location)); 771 expect(true).assertEqual(locationChange2 !=null); 772 }; 773 try { 774 geolocation.on('locationChange', requestInfo, locationChange1); 775 } catch (error) { 776 console.info("[lbs_js] locationChangeOn051 try err." + JSON.stringify(error)); 777 expect(true).assertEqual(JSON.stringify(error) != null); 778 } 779 try { 780 geolocation.on('locationChange', requestInfo, locationChange2); 781 } catch (error) { 782 console.info("[lbs_js] locationChangeOn052 try err." + JSON.stringify(error)); 783 expect(true).assertEqual(JSON.stringify(error) != null); 784 } 785 try { 786 geolocation.off('locationChange', locationChange1); 787 } catch (error) { 788 console.info("[lbs_js] locationChangeOff051 try err." + JSON.stringify(error)); 789 expect(true).assertEqual(JSON.stringify(error) != null); 790 } 791 try { 792 geolocation.off('locationChange', locationChange2); 793 } catch (error) { 794 console.info("[lbs_js] locationChangeOff052 try err." + JSON.stringify(error)); 795 expect(true).assertEqual(JSON.stringify(error) != null); 796 } 797 done(); 798 }) 799 800 /** 801 * @tc.number SUB_HSS_LocationSystem_LocRequest_0700 802 * @tc.name Test locationChange 803 * @tc.desc Initiate a specified continuous positioning request and 804 * set the parameter to high-precision priority positioning request. 805 * @tc.size MEDIUM 806 * @tc.type Function 807 * @tc.level Level 2 808 */ 809 it('SUB_HSS_LocationSystem_LocRequest_0700', 0, async function (done) { 810 enableLocationSwitch(); 811 let requestInfo = {"priority":0x201, "scenario":0x300, "timeInterval":1, 812 "distanceInterval": 5, "maxAccuracy": 10}; 813 var locationChange = (location) => { 814 console.log('locationChanger: data: ' + JSON.stringify(location)); 815 expect(true).assertEqual(locationChange !=null); 816 }; 817 try { 818 geolocation.on('locationChange', requestInfo, locationChange); 819 } catch (error) { 820 console.info("[lbs_js] locationChangeOn07 try err." + JSON.stringify(error)); 821 expect(true).assertEqual(JSON.stringify(error) != null); 822 } 823 try { 824 geolocation.off('locationChange', locationChange); 825 } catch (error) { 826 console.info("[lbs_js] locationChangeOff07 try err." + JSON.stringify(error)); 827 expect(true).assertEqual(JSON.stringify(error) != null); 828 } 829 done(); 830 }) 831 832 /** 833 * @tc.number SUB_HSS_LocationSystem_LocRequest_0800 834 * @tc.name Test locationChange 835 * @tc.desc Initiate a specified continuous positioning request with the parameter 836 * set to fast positioning and priority positioning request. 837 * @tc.size MEDIUM 838 * @tc.type Function 839 * @tc.level Level 2 840 */ 841 it('SUB_HSS_LocationSystem_LocRequest_0800', 0, async function (done) { 842 enableLocationSwitch(); 843 let requestInfo = {"priority":0x203, "scenario":0x300, "timeInterval":5, 844 "distanceInterval": 5, "maxAccuracy": 10}; 845 var locationChange = (location) => { 846 console.log('locationChanger: data: ' + JSON.stringify(location)); 847 expect(true).assertEqual(locationChange !=null); 848 }; 849 try { 850 geolocation.on('locationChange', requestInfo, locationChange); 851 } catch (error) { 852 console.info("[lbs_js] locationChangeOn08 try err." + JSON.stringify(error)); 853 expect(true).assertEqual(JSON.stringify(error) != null); 854 } 855 try { 856 geolocation.off('locationChange', locationChange); 857 } catch (error) { 858 console.info("[lbs_js] locationChangeOff08 try err." + JSON.stringify(error)); 859 expect(true).assertEqual(JSON.stringify(error) != null); 860 } 861 done(); 862 }) 863 864 /** 865 * @tc.number SUB_HSS_LocationSystem_LocRequest_0900 866 * @tc.name Test locationChange 867 * @tc.desc Initiate a specified continuous positioning request with the parameter 868 * set to low power consumption type. 869 * @tc.size MEDIUM 870 * @tc.type Function 871 * @tc.level Level 2 872 */ 873 it('SUB_HSS_LocationSystem_LocRequest_0900', 0, async function (done) { 874 enableLocationSwitch(); 875 let requestInfo = {"priority":0x202, "scenario":0x300, "timeInterval":1, 876 "distanceInterval": 5, "maxAccuracy": 10} 877 var locationChange = (location) => { 878 console.log('locationChanger: data: ' + JSON.stringify(location)); 879 expect(true).assertEqual(locationChange !=null); 880 }; 881 try { 882 geolocation.on('locationChange', requestInfo, locationChange); 883 } catch (error) { 884 console.info("[lbs_js] locationChangeOn09 try err." + JSON.stringify(error)); 885 expect(true).assertEqual(JSON.stringify(error) != null); 886 } 887 try { 888 geolocation.off('locationChange', locationChange); 889 } catch (error) { 890 console.info("[lbs_js] locationChangeOff09 try err." + JSON.stringify(error)); 891 expect(true).assertEqual(JSON.stringify(error) != null); 892 } 893 done(); 894 }) 895 896 /** 897 * @tc.number SUB_HSS_LocationSystem_LocRequest_1000 898 * @tc.name Test locationChange 899 * @tc.desc Initiate a specified continuous location request and set the reporting interval. 900 * @tc.size MEDIUM 901 * @tc.type Function 902 * @tc.level Level 2 903 */ 904 it('SUB_HSS_LocationSystem_LocRequest_1000', 0, async function (done) { 905 enableLocationSwitch(); 906 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":3, 907 "distanceInterval": 0, "maxAccuracy": 0}; 908 var locationChange = (location) => { 909 console.log('locationChanger: data: ' + JSON.stringify(location)); 910 expect(true).assertEqual(locationChange !=null); 911 }; 912 try { 913 geolocation.on('locationChange', requestInfo, locationChange); 914 } catch (error) { 915 console.info("[lbs_js] locationChangeOn10 try err." + JSON.stringify(error)); 916 expect(true).assertEqual(JSON.stringify(error) != null); 917 } 918 try { 919 geolocation.off('locationChange', locationChange); 920 } catch (error) { 921 console.info("[lbs_js] locationChangeOff10 try err." + JSON.stringify(error)); 922 expect(true).assertEqual(JSON.stringify(error) != null); 923 } 924 done(); 925 }) 926 927 /** 928 * @tc.number SUB_HSS_LocationSystem_LocRequest_1100 929 * @tc.name Test locationChange 930 * @tc.desc Initiate a specified continuous location request and set the location reporting interval. 931 * @tc.size MEDIUM 932 * @tc.type Function 933 * @tc.level Level 2 934 */ 935 it('SUB_HSS_LocationSystem_LocRequest_1100', 0, async function (done) { 936 enableLocationSwitch(); 937 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5, 938 "distanceInterval": 0, "maxAccuracy": 0}; 939 var locationChange = (location) => { 940 console.log('locationChanger: data: ' + JSON.stringify(location)); 941 expect(true).assertEqual(locationChange !=null); 942 }; 943 try { 944 geolocation.on('locationChange', requestInfo, locationChange); 945 } catch (error) { 946 console.info("[lbs_js] locationChangeOn11 try err." + JSON.stringify(error)); 947 expect(true).assertEqual(JSON.stringify(error) != null); 948 } 949 try { 950 geolocation.off('locationChange', locationChange); 951 } catch (error) { 952 console.info("[lbs_js] locationChangeOff11 try err." + JSON.stringify(error)); 953 expect(true).assertEqual(JSON.stringify(error) != null); 954 } 955 done(); 956 }) 957 958 /** 959 * @tc.number SUB_HSS_LocationSystem_LocRequest_1200 960 * @tc.name Test locationChange 961 * @tc.desc Initiate a specified continuous location request and set the interval for reporting exceptions. 962 * @tc.size MEDIUM 963 * @tc.type Function 964 * @tc.level Level 2 965 */ 966 it('SUB_HSS_LocationSystem_LocRequest_1200', 0, async function (done) { 967 enableLocationSwitch(); 968 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 969 "distanceInterval": 0, "maxAccuracy": 0}; 970 var locationChange = (location) => { 971 console.log('locationChanger: data: ' + JSON.stringify(location)); 972 expect(true).assertEqual(locationChange !=null); 973 }; 974 try { 975 geolocation.on('locationChange', requestInfo, locationChange); 976 } catch (error) { 977 console.info("[lbs_js] locationChangeOn12 try err." + JSON.stringify(error)); 978 expect(true).assertEqual(JSON.stringify(error) != null); 979 } 980 try { 981 geolocation.off('locationChange', locationChange); 982 } catch (error) { 983 console.info("[lbs_js] locationChangeOff12 try err." + JSON.stringify(error)); 984 expect(true).assertEqual(JSON.stringify(error) != null); 985 } 986 done(); 987 }) 988 989 /** 990 * @tc.number SUB_HSS_LocationSystem_LocRequest_1300 991 * @tc.name Test locationChange 992 * @tc.desc Initiate a specified continuous location request and set the interval for reporting abnormal locations. 993 * @tc.size MEDIUM 994 * @tc.type Function 995 * @tc.level Level 2 996 */ 997 it('SUB_HSS_LocationSystem_LocRequest_1300', 0, async function (done) { 998 enableLocationSwitch(); 999 let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1000 "distanceInterval": 0, "maxAccuracy": 0}; 1001 let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1002 "distanceInterval": 0, "maxAccuracy": 0}; 1003 var locationChange1 = (location) => { 1004 console.log('locationChanger: data: ' + JSON.stringify(location)); 1005 expect(true).assertEqual(locationChange1 !=null); 1006 }; 1007 var locationChange2 = (location) => { 1008 console.log('locationChanger: data: ' + JSON.stringify(location)); 1009 expect(true).assertEqual(locationChange2 !=null); 1010 }; 1011 try { 1012 geolocation.on('locationChange', requestInfo1, locationChange1); 1013 } catch (error) { 1014 console.info("[lbs_js] locationChangeOn131 try err." + JSON.stringify(error)); 1015 expect(true).assertEqual(JSON.stringify(error) != null); 1016 } 1017 try { 1018 geolocation.off('locationChange', locationChange1); 1019 } catch (error) { 1020 console.info("[lbs_js] locationChangeOff131 try err." + JSON.stringify(error)); 1021 expect(true).assertEqual(JSON.stringify(error) != null); 1022 } 1023 try { 1024 geolocation.on('locationChange', requestInfo2, locationChange2); 1025 } catch (error) { 1026 console.info("[lbs_js] locationChangeOn132 try err." + JSON.stringify(error)); 1027 expect(true).assertEqual(JSON.stringify(error) != null); 1028 } 1029 try { 1030 geolocation.off('locationChange', locationChange2); 1031 } catch (error) { 1032 console.info("[lbs_js] locationChangeOff132 try err." + JSON.stringify(error)); 1033 expect(true).assertEqual(JSON.stringify(error) != null); 1034 } 1035 done(); 1036 }) 1037 1038 /** 1039 * @tc.number SUB_HSS_LocationSystem_LocRequest_1400 1040 * @tc.name Test locationChange 1041 * @tc.desc Initiate a specified continuous positioning request and set the positioning reporting precision. 1042 * @tc.size MEDIUM 1043 * @tc.type Function 1044 * @tc.level Level 2 1045 */ 1046 it('SUB_HSS_LocationSystem_LocRequest_1400', 0, async function (done) { 1047 enableLocationSwitch(); 1048 let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1049 "distanceInterval": 0, "maxAccuracy": 5}; 1050 let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1051 "distanceInterval": 0, "maxAccuracy": 2}; 1052 var locationChange1 = (location) => { 1053 console.log('locationChanger: data: ' + JSON.stringify(location)); 1054 expect(true).assertEqual(locationChange1 !=null); 1055 }; 1056 var locationChange2 = (location) => { 1057 console.log('locationChanger: data: ' + JSON.stringify(location)); 1058 expect(true).assertEqual(locationChange2 !=null); 1059 }; 1060 try { 1061 geolocation.on('locationChange', requestInfo1, locationChange1); 1062 } catch (error) { 1063 console.info("[lbs_js] locationChangeOn141 try err." + JSON.stringify(error)); 1064 expect(true).assertEqual(JSON.stringify(error) != null); 1065 } 1066 try { 1067 geolocation.off('locationChange', locationChange1); 1068 } catch (error) { 1069 console.info("[lbs_js] locationChangeOff141 try err." + JSON.stringify(error)); 1070 expect(true).assertEqual(JSON.stringify(error) != null); 1071 } 1072 try { 1073 geolocation.on('locationChange', requestInfo2, locationChange2); 1074 } catch (error) { 1075 console.info("[lbs_js] locationChangeOn142 try err." + JSON.stringify(error)); 1076 expect(true).assertEqual(JSON.stringify(error) != null); 1077 } 1078 try { 1079 geolocation.off('locationChange', locationChange2); 1080 } catch (error) { 1081 console.info("[lbs_js] locationChangeOff142 try err." + JSON.stringify(error)); 1082 expect(true).assertEqual(JSON.stringify(error) != null); 1083 } 1084 done(); 1085 }) 1086 1087 /** 1088 * @tc.number SUB_HSS_LocationSystem_LocRequest_1500 1089 * @tc.name Test locationChange 1090 * @tc.desc Initiate a specified continuous location request and set the reporting precision of abnormal location. 1091 * @tc.size MEDIUM 1092 * @tc.type Function 1093 * @tc.level Level 2 1094 */ 1095 it('SUB_HSS_LocationSystem_LocRequest_1500', 0, async function (done) { 1096 enableLocationSwitch(); 1097 let requestInfo1 = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1098 "distanceInterval": 0, "maxAccuracy": 0}; 1099 let requestInfo2 = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1100 "distanceInterval": 0, "maxAccuracy": -1}; 1101 var locationChange1 = (location) => { 1102 console.log('locationChanger: data: ' + JSON.stringify(location)); 1103 expect(true).assertEqual(locationChange1 !=null); 1104 }; 1105 var locationChange2 = (location) => { 1106 console.log('locationChanger: data: ' + JSON.stringify(location)); 1107 expect(true).assertEqual(locationChange2 !=null); 1108 }; 1109 try { 1110 geolocation.on('locationChange', requestInfo1, locationChange1); 1111 } catch (error) { 1112 console.info("[lbs_js] locationChangeOn151 try err." + JSON.stringify(error)); 1113 expect(true).assertEqual(JSON.stringify(error) != null); 1114 } 1115 try { 1116 geolocation.off('locationChange', locationChange1); 1117 } catch (error) { 1118 console.info("[lbs_js] locationChangeOff151 try err." + JSON.stringify(error)); 1119 expect(true).assertEqual(JSON.stringify(error) != null); 1120 } 1121 try { 1122 geolocation.on('locationChange', requestInfo2, locationChange2); 1123 } catch (error) { 1124 console.info("[lbs_js] locationChangeOn152 try err." + JSON.stringify(error)); 1125 expect(true).assertEqual(JSON.stringify(error) != null); 1126 } 1127 try { 1128 geolocation.off('locationChange', locationChange2); 1129 } catch (error) { 1130 console.info("[lbs_js] locationChangeOff152 try err." + JSON.stringify(error)); 1131 expect(true).assertEqual(JSON.stringify(error) != null); 1132 } 1133 done(); 1134 }) 1135 1136 /** 1137 * @tc.number SUB_HSS_LocationSystem_LastLoc_0100 1138 * @tc.name Test getLastLocation 1139 * @tc.desc Obtain the last location after a single location. 1140 * @tc.size MEDIUM 1141 * @tc.type Function 1142 * @tc.level Level 2 1143 */ 1144 it('SUB_HSS_LocationSystem_LastLoc_0100', 0, async function(done) { 1145 enableLocationSwitch(); 1146 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1147 "distanceInterval": 0, "maxAccuracy": 0}; 1148 var locationChange = (location) => { 1149 console.log('locationChanger: data: ' + JSON.stringify(location)); 1150 expect(true).assertEqual(locationChange !=null); 1151 }; 1152 try { 1153 geolocation.on('locationChange', requestInfo, locationChange); 1154 } catch (error) { 1155 console.info("[lbs_js] locationChangeOn1 try err." + JSON.stringify(error)); 1156 expect(true).assertEqual(JSON.stringify(error) != null); 1157 } 1158 try { 1159 geolocation.off('locationChange', locationChange); 1160 } catch (error) { 1161 console.info("[lbs_js] locationChangeOff1 try err." + JSON.stringify(error)); 1162 expect(true).assertEqual(JSON.stringify(error) != null); 1163 } 1164 await geolocation.getLastLocation().then((result) => { 1165 console.info('[lbs_js] getLastLocation promise result: ' + JSON.stringify(result)); 1166 expect(true).assertEqual(JSON.stringify(result) != null); 1167 console.info('[lbs_js] getLastLocation latitude: ' + result.latitude + 1168 ' longitude: ' + result.longitude +' altitude: ' + result.altitude 1169 +' accuracy: ' + result.accuracy+' speed: ' + result.speed + 1170 'timeStamp: ' + result.timeStamp+'direction:' + result.direction+' timeSinceBoot: ' 1171 + result.timeSinceBoot +'additions: ' + result.additions+' additionSize' + result.additionSize 1172 + 'isFromMock' +result.isFromMock); 1173 }).catch((error) => { 1174 console.info("[lbs_js] getLastLocation promise then error:" + JSON.stringify(error)); 1175 console.info('[lbs_js] not support now'); 1176 expect(true).assertEqual(JSON.stringify(error) != null); 1177 }); 1178 done(); 1179 }) 1180 1181 /** 1182 * @tc.number SUB_HSS_LocationSystem_LastLoc_0200 1183 * @tc.name Test getLastLocation 1184 * @tc.desc Obtain the last location after continuous positioning. 1185 * @tc.size MEDIUM 1186 * @tc.type Function 1187 * @tc.level Level 2 1188 */ 1189 it('SUB_HSS_LocationSystem_LastLoc_0200', 0, async function (done) { 1190 enableLocationSwitch(); 1191 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1192 "distanceInterval": 0, "maxAccuracy": 0}; 1193 var locationChange = (location) => { 1194 console.log('locationChanger: data: ' + JSON.stringify(location)); 1195 expect(true).assertEqual(locationChange !=null); 1196 }; 1197 try { 1198 geolocation.on('locationChange', requestInfo, locationChange); 1199 } catch (error) { 1200 console.info("[lbs_js] locationChangeOn2 try err." + JSON.stringify(error)); 1201 expect(true).assertEqual(JSON.stringify(error) != null); 1202 } 1203 try { 1204 geolocation.off('locationChange', locationChange); 1205 } catch (error) { 1206 console.info("[lbs_js] locationChangeOff2 try err." + JSON.stringify(error)); 1207 expect(true).assertEqual(JSON.stringify(error) != null); 1208 } 1209 try { 1210 geolocation.getLastLocation((err, data) => { 1211 if (err) { 1212 console.info('[lbs_js] getLastLocation2 callback err:' + JSON.stringify(err)); 1213 expect(true).assertEqual(err !=null); 1214 } else { 1215 console.info('[lbs_js] getLastLocation2 callback result:' + JSON.stringify(data)); 1216 expect(true).assertEqual(data !=null); 1217 } 1218 }); 1219 } catch (error) { 1220 console.info("[lbs_js] getLastLocation2 callback try err." + JSON.stringify(error)); 1221 expect(true).assertEqual(JSON.stringify(error) != null); 1222 } 1223 await sleep(1000); 1224 done(); 1225 }) 1226 1227 /** 1228 * @tc.number SUB_HSS_LocationSystem_Gnss_0100 1229 * @tc.name Test gnssStatusChange 1230 * @tc.desc Monitoring Satellite Information Reporting 1231 * @tc.size MEDIUM 1232 * @tc.type Function 1233 * @tc.level Level 2 1234 */ 1235 it('SUB_HSS_LocationSystem_Gnss_0100', 0, async function (done) { 1236 await changedLocationMode(); 1237 var gnssStatusCb = (satelliteStatusInfo) => { 1238 console.info('gnssStatusChange: ' + satelliteStatusInfo); 1239 expect(true).assertEqual(satelliteStatusInfo != null) 1240 console.info('[lbs_js] SatelliteStatusInfo satellitesNumber: ' + data[0].satellitesNumber + 1241 'satelliteIds' + data[0].satelliteIds +'carrierToNoiseDensitys'+ data[0].carrierToNoiseDensitys 1242 +'altitudes' + data[0].altitudes+' azimuths: ' + data[0].azimuths + 1243 'carrierFrequencies: ' + data[0].carrierFrequencies); 1244 } 1245 try { 1246 geolocation.on('gnssStatusChange', gnssStatusCb); 1247 } catch (error) { 1248 console.info("[lbs_js] gnssStatusChangeOn1 try err." + JSON.stringify(error)); 1249 expect(true).assertEqual(JSON.stringify(error) != null); 1250 } 1251 enableLocationSwitch(); 1252 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1253 "distanceInterval": 0, "maxAccuracy": 0}; 1254 var locationChange = (location) => { 1255 console.log('locationChanger: data: ' + JSON.stringify(location)); 1256 expect(true).assertEqual(locationChange !=null); 1257 }; 1258 try { 1259 geolocation.on('locationChange', requestInfo, locationChange); 1260 } catch (error) { 1261 console.info("[lbs_js] locationChangeOn1 try err." + JSON.stringify(error)); 1262 expect(true).assertEqual(JSON.stringify(error) != null); 1263 } 1264 try { 1265 geolocation.off('gnssStatusChange', gnssStatusCb); 1266 } catch (error) { 1267 console.info("[lbs_js] gnssStatusChangeOff1 try err." + JSON.stringify(error)); 1268 expect(true).assertEqual(JSON.stringify(error) != null); 1269 } 1270 try { 1271 geolocation.off('locationChange', locationChange); 1272 } catch (error) { 1273 console.info("[lbs_js] locationChangeOff1 try err." + JSON.stringify(error)); 1274 expect(true).assertEqual(JSON.stringify(error) != null); 1275 } 1276 done(); 1277 }) 1278 1279 /** 1280 * @tc.number SUB_HSS_LocationSystem_Gnss_0200 1281 * @tc.name Test nmeaMessageChange 1282 * @tc.desc Monitoring NMEA Information Reporting 1283 * @tc.size MEDIUM 1284 * @tc.type Function 1285 * @tc.level Level 2 1286 */ 1287 it('SUB_HSS_LocationSystem_Gnss_0200', 0, async function (done) { 1288 await changedLocationMode(); 1289 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1290 "distanceInterval": 0, "maxAccuracy": 0}; 1291 var nmeaCb = (str) => { 1292 console.log('nmeaMessageChange: ' + str); 1293 } 1294 var locationChange = (location) => { 1295 console.log('locationChanger: data: ' + JSON.stringify(location)); 1296 expect(true).assertEqual(locationChange !=null); 1297 }; 1298 try { 1299 geolocation.on('nmeaMessageChange', nmeaCb); 1300 } catch (error) { 1301 console.info("[lbs_js] nmeaChangeOn2 try err." + JSON.stringify(error)); 1302 expect(true).assertEqual(JSON.stringify(error) != null); 1303 } 1304 try { 1305 geolocation.on('locationChange', requestInfo, locationChange); 1306 } catch (error) { 1307 console.info("[lbs_js] locationChangeOn2 try err." + JSON.stringify(error)); 1308 expect(true).assertEqual(JSON.stringify(error) != null); 1309 } 1310 try { 1311 geolocation.off('nmeaMessageChange', nmeaCb); 1312 } catch (error) { 1313 console.info("[lbs_js] nmeaChangeOff2 try err." + JSON.stringify(error)); 1314 expect(true).assertEqual(JSON.stringify(error) != null); 1315 } 1316 try { 1317 geolocation.off('locationChange', locationChange); 1318 } catch (error) { 1319 console.info("[lbs_js] locationChangeOff2 try err." + JSON.stringify(error)); 1320 expect(true).assertEqual(JSON.stringify(error) != null); 1321 } 1322 done(); 1323 }) 1324 1325 /** 1326 * @tc.number SUB_HSS_LocationSystem_Batching_0100 1327 * @tc.name Test cachedGnssLocationsReporting 1328 * @tc.desc Setting the Gnss Batching Reporting Interval 1329 * @tc.size MEDIUM 1330 * @tc.type Function 1331 * @tc.level Level 2 1332 */ 1333 it('SUB_HSS_LocationSystem_Batching_0100', 0, async function (done) { 1334 var cachedLocationsCb1 = (locations) => { 1335 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 1336 expect(true).assertEqual(locations !=null); 1337 } 1338 var CachedGnssLoactionsRequest1 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false}; 1339 try { 1340 geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest1, cachedLocationsCb1); 1341 } catch (error) { 1342 console.info("[lbs_js] cachedGnssOn11 try err." + JSON.stringify(error)); 1343 expect(true).assertEqual(JSON.stringify(error) != null); 1344 } 1345 try { 1346 geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb1); 1347 } catch (error) { 1348 console.info("[lbs_js] cachedGnssOff11 try err." + JSON.stringify(error)); 1349 expect(true).assertEqual(JSON.stringify(error) != null); 1350 } 1351 var cachedLocationsCb2 = (locations) => { 1352 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 1353 expect(true).assertEqual(locations !=null); 1354 } 1355 var CachedGnssLoactionsRequest2 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false}; 1356 try { 1357 geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest2, cachedLocationsCb2); 1358 } catch (error) { 1359 console.info("[lbs_js] cachedGnssOn12 try err." + JSON.stringify(error)); 1360 expect(true).assertEqual(JSON.stringify(error) != null); 1361 } 1362 try { 1363 geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb1); 1364 } catch (error) { 1365 console.info("[lbs_js] cachedGnssOff12 try err." + JSON.stringify(error)); 1366 expect(true).assertEqual(JSON.stringify(error) != null); 1367 } 1368 done(); 1369 }) 1370 1371 /** 1372 * @tc.number SUB_HSS_LocationSystem_Batching_0200 1373 * @tc.name Test cachedGnssLocationsReporting 1374 * @tc.desc Setting the Gnss Batching Cache Queue to Be Reported When the Gnss Batching Cache Queue Is Full 1375 * @tc.size MEDIUM 1376 * @tc.type Function 1377 * @tc.level Level 2 1378 */ 1379 it('SUB_HSS_LocationSystem_Batching_0200', 0, async function (done) { 1380 var cachedLocationsCb = (locations) => { 1381 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 1382 expect(true).assertEqual(locations !=null); 1383 } 1384 var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; 1385 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1386 "distanceInterval": 0, "maxAccuracy": 0}; 1387 try { 1388 geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); 1389 } catch (error) { 1390 console.info("[lbs_js] cachedGnssOn2 try err." + JSON.stringify(error)); 1391 expect(true).assertEqual(JSON.stringify(error) != null); 1392 } 1393 try { 1394 geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); 1395 } catch (error) { 1396 console.info("[lbs_js] cachedGnssOff2 try err." + JSON.stringify(error)); 1397 expect(true).assertEqual(JSON.stringify(error) != null); 1398 } 1399 done(); 1400 }) 1401 1402 /** 1403 * @tc.number SUB_HSS_LocationSystem_Batching_0300 1404 * @tc.name Test getCachedGnssLocationsSize 1405 * @tc.desc Obtains the number of GNSS data records in the batching process. 1406 * @tc.size MEDIUM 1407 * @tc.type Function 1408 * @tc.level Level 2 1409 */ 1410 it('SUB_HSS_LocationSystem_Batching_0300', 0, async function (done) { 1411 var cachedLocationsCb = (locations) => { 1412 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 1413 expect(true).assertEqual(locations !=null); 1414 } 1415 var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; 1416 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1417 "distanceInterval": 0, "maxAccuracy": 0}; 1418 try { 1419 geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); 1420 } catch (error) { 1421 console.info("[lbs_js] cachedGnssOn2 try err." + JSON.stringify(error)); 1422 expect(true).assertEqual(JSON.stringify(error) != null); 1423 } 1424 try { 1425 geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); 1426 } catch (error) { 1427 console.info("[lbs_js] cachedGnssOff2 try err." + JSON.stringify(error)); 1428 expect(true).assertEqual(JSON.stringify(error) != null); 1429 } 1430 try { 1431 geolocation.getCachedGnssLocationsSize((err, data) => { 1432 if (err) { 1433 console.info('[lbs_js] getCachedGnssLocationsSize callback err:' + JSON.stringify(err)); 1434 expect(true).assertEqual(err != null); 1435 }else { 1436 console.info("[lbs_js] getCachedGnssLocationsSize callback data is:" + JSON.stringify(data)); 1437 expect(true).assertEqual(data != null); 1438 } 1439 }); 1440 } catch (error) { 1441 console.info("[lbs_js] getCachedGnssLocationsS callback try err:" + JSON.stringify(data)); 1442 expect(true).assertEqual(data != null); 1443 } 1444 await sleep(1000); 1445 done(); 1446 }) 1447 1448 /** 1449 * @tc.number SUB_HSS_LocationSystem_Batching_0400 1450 * @tc.name Test getCachedGnssLocationsSize 1451 * @tc.desc Obtains the number of GNSS data records in the batching process. 1452 * @tc.size MEDIUM 1453 * @tc.type Function 1454 * @tc.level Level 2 1455 */ 1456 it('SUB_HSS_LocationSystem_Batching_0400', 0, async function (done) { 1457 var cachedLocationsCb = (locations) => { 1458 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 1459 expect(true).assertEqual(locations !=null); 1460 } 1461 var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; 1462 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1463 "distanceInterval": 0, "maxAccuracy": 0}; 1464 try { 1465 geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); 1466 } catch (error) { 1467 console.info("[lbs_js] cachedGnssOn2 try err." + JSON.stringify(error)); 1468 expect(true).assertEqual(JSON.stringify(error) != null); 1469 } 1470 try { 1471 geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); 1472 } catch (error) { 1473 console.info("[lbs_js] cachedGnssOff2 try err." + JSON.stringify(error)); 1474 expect(true).assertEqual(JSON.stringify(error) != null); 1475 } 1476 try { 1477 await geolocation.getCachedGnssLocationsSize().then((result) => { 1478 console.info('[lbs_js] getCachedGnssLocationsSiz promise '+ JSON.stringify(result)); 1479 expect(true).assertEqual(result != null); 1480 }).catch((error) => { 1481 console.info("[lbs_js] promise then error." + JSON.stringify(error)); 1482 expect(true).assertEqual(error != null); 1483 }); 1484 } catch (error) { 1485 console.info("[lbs_js] getCachedGnssLocationsS promise try err." + JSON.stringify(error)); 1486 expect(true).assertEqual(JSON.stringify(error) != null); 1487 } 1488 done(); 1489 }) 1490 1491 /** 1492 * @tc.number SUB_HSS_LocationSystem_Batching_0500 1493 * @tc.name Test flushCachedGnssLocations 1494 * @tc.desc Obtains the GNSS data of the current batching. 1495 * @tc.size MEDIUM 1496 * @tc.type Function 1497 * @tc.level Level 2 1498 */ 1499 it('SUB_HSS_LocationSystem_Batching_0500', 0, async function (done) { 1500 var cachedLocationsCb = (locations) => { 1501 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 1502 expect(true).assertEqual(locations !=null); 1503 } 1504 var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; 1505 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1506 "distanceInterval": 0, "maxAccuracy": 0}; 1507 try { 1508 geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); 1509 } catch (error) { 1510 console.info("[lbs_js] cachedGnssOn2 try err." + JSON.stringify(error)); 1511 expect(true).assertEqual(JSON.stringify(error) != null); 1512 } 1513 try { 1514 geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); 1515 } catch (error) { 1516 console.info("[lbs_js] cachedGnssOff2 try err." + JSON.stringify(error)); 1517 expect(true).assertEqual(JSON.stringify(error) != null); 1518 } 1519 try { 1520 geolocation.flushCachedGnssLocations((err, data) => { 1521 if (err) { 1522 console.info('[lbs_js] flushCachedGnssLocations callback err:' + JSON.stringify(err)); 1523 expect(true).assertEqual(err != null); 1524 }else { 1525 console.info("[lbs_js] flushCachedGnssLocations callback data:" + JSON.stringify(data)); 1526 expect(true).assertEqual(data != null); 1527 } 1528 }); 1529 } catch (error) { 1530 console.info("[lbs_js] flushCachedGnssLoc callback try err: " + JSON.stringify(data)); 1531 expect(true).assertEqual(JSON.stringify(error) != null); 1532 } 1533 await sleep(1000); 1534 done(); 1535 }) 1536 1537 /** 1538 * @tc.number SUB_HSS_LocationSystem_Batching_0600 1539 * @tc.name Test flushCachedGnssLocations 1540 * @tc.desc Obtain the GNSS data of the current batching. 1541 * @tc.size MEDIUM 1542 * @tc.type Function 1543 * @tc.level Level 2 1544 */ 1545 it('SUB_HSS_LocationSystem_Batching_0600', 0, async function (done) { 1546 var cachedLocationsCb = (locations) => { 1547 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 1548 expect(true).assertEqual(locations !=null); 1549 } 1550 var CachedGnssLoactionsRequest = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': true}; 1551 let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0, 1552 "distanceInterval": 0, "maxAccuracy": 0}; 1553 try { 1554 geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb); 1555 } catch (error) { 1556 console.info("[lbs_js] cachedGnssOn2 try err." + JSON.stringify(error)); 1557 expect(true).assertEqual(JSON.stringify(error) != null); 1558 } 1559 try { 1560 geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb); 1561 } catch (error) { 1562 console.info("[lbs_js] cachedGnssOff2 try err." + JSON.stringify(error)); 1563 expect(true).assertEqual(JSON.stringify(error) != null); 1564 } 1565 try { 1566 await geolocation.flushCachedGnssLocations().then((result) => { 1567 console.info('[lbs_js] flushCachedGnssLocations promise '+ JSON.stringify(result)); 1568 expect(true).assertEqual(result != null); 1569 }).catch((error) => { 1570 console.info("[lbs_js] promise then error." + JSON.stringify(error)); 1571 expect(true).assertEqual(error != null); 1572 }); 1573 } catch (error) { 1574 console.info("[lbs_js] cachedGnssOff2 try err." + JSON.stringify(error)); 1575 expect(true).assertEqual(JSON.stringify(error) != null); 1576 } 1577 done(); 1578 }) 1579 1580 /** 1581 * @tc.number SUB_HSS_LocationSystem_GeoFence_0100 1582 * @tc.name Test fenceStatusChange 1583 * @tc.desc Gnss fence function test 1584 * @tc.size MEDIUM 1585 * @tc.type Function 1586 * @tc.level Level 1 1587 */ 1588 it('SUB_HSS_LocationSystem_GeoFence_0100', 0, async function (done) { 1589 await changedLocationMode(); 1590 let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; 1591 let geofenceRequest = {"priority":0x200, "scenario":0x301, "geofence": geofence}; 1592 let want = (wantAgent) => { 1593 console.log('wantAgent: ' + JSON.stringify(wantAgent)); 1594 }; 1595 try { 1596 geolocation.on('fenceStatusChange', geofenceRequest, 1597 (want) => { 1598 if(err){ 1599 return console.info("[lbs_js] fenceStatusChangeOn callback err:" + err); 1600 } 1601 console.info("[lbs_js] fenceStatusChange callback result: " + JSON.stringify(want)); 1602 expect(true).assertEqual(want !=null); 1603 done(); 1604 }); 1605 } catch (error) { 1606 console.info("[lbs_js] fenceStatusChangeOn1 try err." + JSON.stringify(error)); 1607 expect(true).assertEqual(JSON.stringify(error) != null); 1608 } 1609 try { 1610 geolocation.off('fenceStatusChange',geofenceRequest, 1611 (want) => { 1612 if(err){ 1613 return console.info("[lbs_js] fenceStatusChange callback err:" + err); 1614 } 1615 console.info("[lbs_js] off fenceStatusChange callback result:" + JSON.stringify(want)); 1616 expect(true).assertEqual(want !=null); 1617 }); 1618 } catch (error) { 1619 console.info("[lbs_js] fenceStatusChangeOff1 try err." + JSON.stringify(error)); 1620 expect(true).assertEqual(JSON.stringify(error) != null); 1621 } 1622 await sleep(1000); 1623 done(); 1624 }) 1625 1626 /** 1627 * @tc.number SUB_HSS_LocationSystem_GeoFence_0500 1628 * @tc.name Test fenceStatusChange 1629 * @tc.desc Test the function of locating the validity period of the fence. 1630 * @tc.size MEDIUM 1631 * @tc.type Function 1632 * @tc.level Level 1 1633 */ 1634 it('SUB_HSS_LocationSystem_GeoFence_0500', 0, async function (done) { 1635 await changedLocationMode(); 1636 let geofence = {"latitude": 31.12, "longitude": 121.11, "radius": 1,"expiration": ""}; 1637 let geofenceRequest = {"priority":0x203, "scenario":0x301, "geofence": geofence}; 1638 try { 1639 geolocation.on('fenceStatusChange', geofenceRequest, 1640 (want) => { 1641 if(err){ 1642 return console.info("[lbs_js] fenceStatusChangeOn callback err:" + err); 1643 } 1644 console.info("[lbs_js] fenceStatusChange callback, result: " + JSON.stringify(want)); 1645 expect(true).assertEqual(want !=null); 1646 done(); 1647 }); 1648 } catch (error) { 1649 console.info("[lbs_js] fenceStatusChangeOn5 try err." + JSON.stringify(error)); 1650 expect(true).assertEqual(JSON.stringify(error) != null); 1651 } 1652 try { 1653 geolocation.off('fenceStatusChange',geofenceRequest, 1654 (want) => { 1655 if(err){ 1656 return console.info("[lbs_js] fenceStatusChange callback err:" + err); 1657 } 1658 console.info("[lbs_js] fenceStatusChangeOff callback result:" + JSON.stringify(want)); 1659 expect(true).assertEqual(want !=null); 1660 }); 1661 } catch (error) { 1662 console.info("[lbs_js] fenceStatusChangeOff5 try err." + JSON.stringify(error)); 1663 expect(true).assertEqual(JSON.stringify(error) != null); 1664 } 1665 done(); 1666 }) 1667 1668 }) 1669} 1670 1671 1672 1673