LocationTest.test.js 55.7 KB
Newer Older
Q
q00313334 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import geolocation from '@ohos.geolocation';
import { LocationEventListener } from '@ohos.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
20
import osaccount from '@ohos.account.osAccount'
Q
quanli 已提交
21
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
Q
q00313334 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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(){
    await geolocation.isLocationEnabled().then(async(result) => {
Q
quanli 已提交
38 39 40
        console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
        if(!result){
            await geolocation.requestEnableLocation().then(async(result) => {
Q
quanli 已提交
41
                await sleep(3000);
Q
quanli 已提交
42 43 44 45 46 47 48 49
                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();
            });
        }
    });
    await geolocation.isLocationEnabled().then(async(result) => {
Q
quanli 已提交
50
        console.info('[lbs_js] check LocationSwitchState result: ' + JSON.stringify(result));
Q
quanli 已提交
51
    });
Q
q00313334 已提交
52 53
}

Q
quanli 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
async function enableLocationSwitch(){
    function enableLocationSwitchCallback(){
        return new Promise((resolve, reject)=>{
            geolocation.requestEnableLocation((err, data) => {
                if (err) {
                    console.info('[lbs_js]  requestEnableLocation callback err is : ' + err );
                }else {
                    console.info("[lbs_js] requestEnableLocation callback data: " + data);
                    expect(data).assertTrue();
                }
            });
        })
    }
    await enableLocationSwitchCallback();
    done();

}


Q
q00313334 已提交
73
async function applyPermission() {
Q
quanli 已提交
74
    let osAccountManager = osaccount.getAccountManager();
Q
quanli 已提交
75
    console.info("=== getAccountManager finish");
Q
quanli 已提交
76
    let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
Q
quanli 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    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');
    }
Q
q00313334 已提交
98 99
}

Q
quanli 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113
export default function geolocationTest_geo3() {

    describe('geolocationTest_geo3', function () {
        beforeAll(async function (done) {
            console.info('beforeAll case');
            await applyPermission();
            done();
        })
    
        beforeEach(function () {
            console.info('beforeEach case');
        })
        afterEach(function () {
        })
Q
q00313334 已提交
114 115 116


    /**
Q
quanli 已提交
117 118 119
     * @tc.number SUB_HSS_LocationSystem_LocSwitch_0300
     * @tc.name Test requestrequestEnableLocation api
     * @tc.desc Enabling the Location Service Function for a Third-Party App - Callback
Q
q00313334 已提交
120 121 122 123
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
124
     it('SUB_HSS_LocationSystem_LocSwitch_0300', 0, async function (done) {
Q
quanli 已提交
125
        geolocation.isLocationEnabled(async (err, data) => {
Q
q00313334 已提交
126
            if (err) {
Q
quanli 已提交
127 128 129 130
                console.info('[lbs_js] getLocationSwitchState callback err is : ' + JSON.stringify(err));

            } else {
                console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data));
Q
q00313334 已提交
131 132 133
                expect(data).assertTrue();
            }
            done()
Q
quanli 已提交
134 135
        })
    });
Q
q00313334 已提交
136 137

    /**
Q
quanli 已提交
138 139 140
     * @tc.number LocSwitch_0400
     * @tc.name Test requestrequestEnableLocation api.
     * @tc.desc Enabling the Location Service Function for a Third-Party Application -Promise Mode
Q
q00313334 已提交
141 142 143 144
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
145
    it('SUB_HSS_LocationSystem_LocSwitch_0400', 0, async function (done) {
Q
quanli 已提交
146 147 148 149 150
        await geolocation.isLocationEnabled().then((result1) => {
            console.info('[lbs_js] getLocationSwitchStateLocSwitch_0004 result: ' + JSON.stringify(result1));
            expect(result1).assertTrue();
        }).catch((error) => {
            expect().assertFail();
Q
q00313334 已提交
151
        });
Q
quanli 已提交
152 153
        done();
    });
Q
q00313334 已提交
154 155

    /**
Q
quanli 已提交
156 157 158
     * @tc.number SUB_HSS_LocationSystem_LocSwitch_0500
     * @tc.name Test locationServiceState api .
     * @tc.desc Subscribe to the location service status change.
Q
q00313334 已提交
159 160 161 162
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
163
    it('SUB_HSS_LocationSystem_LocSwitch_0500', 0, async function (done) {
Q
quanli 已提交
164 165 166 167 168 169
        console.log('just for overwriting,locationServiceState test need system api ');
        var locationServiceState = (state) => {
            console.log('locationServiceState: state: ' + JSON.stringify(state));
        }
        geolocation.on('locationServiceState', locationServiceState);
        geolocation.off('locationServiceState', locationServiceState);
Q
quanli 已提交
170
	expect(true).assertTrue();
Q
quanli 已提交
171
        done();
Q
q00313334 已提交
172 173 174
    })

    /**
Q
quanli 已提交
175
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0100
Q
quanli 已提交
176 177
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario..
Q
q00313334 已提交
178 179 180 181
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
182
    it('SUB_HSS_LocationSystem_SingleLoc_0100', 0, async function (done) {
Q
quanli 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
        let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 0 };
        function getCurrentLocationCallback() {
            return new Promise((resolve, reject) => {
                geolocation.getCurrentLocation(currentLocationRequest, (err, result) => {
                    if (err) {
                        console.info("getCurrentLocation callback err:  " + JSON.stringify(err));
                        expect(true).assertEqual(err != null);
                        console.info('getCurrentLocationCallback reject after')
                    } else {
                        console.info("getCurrentLocation callback, result:  " + JSON.stringify(result));
                        expect(true).assertEqual(result != null);
                        resolve();
                    }
                });
            })
        }
        console.info('getCurrentLocationCallback  start');
Q
quanli 已提交
200 201 202 203 204 205 206
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info("getCurrentLocation callback_0003, result:  " + JSON.stringify(result));
            expect(true).assertEqual(result != null);
        }).catch(error => {
            console.info('getCurrentLocation callback_0003:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        })
Q
quanli 已提交
207
        done();
Q
q00313334 已提交
208 209 210
    })

    /**
Q
quanli 已提交
211
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0200
Q
quanli 已提交
212 213
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request in a specified scenario and set the navigation scenario..
Q
q00313334 已提交
214 215 216 217
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
218
    it('SUB_HSS_LocationSystem_SingleLoc_0200', 0, async function (done) {
Q
quanli 已提交
219 220 221 222 223 224 225 226 227
        let currentLocationRequest = { "priority": 0x203, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 0 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation_0002 promise err:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done();
Q
q00313334 已提交
228 229 230
    })

    /**
Q
quanli 已提交
231
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0300
Q
quanli 已提交
232 233
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request in a specified scenario and set the track tracing scenario.
Q
q00313334 已提交
234 235 236 237
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
238
    it('SUB_HSS_LocationSystem_SingleLoc_0300', 0, async function (done) {
Q
quanli 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
        let currentLocationRequest = { "priority": 0x200, "scenario": 0x302, "timeoutMs": 1000, "maxAccuracy": 10 };
        function getCurrentLocationCallback() {
            return new Promise((resolve, reject) => {
                geolocation.getCurrentLocation(currentLocationRequest, (err, result) => {
                    if (err) {
                        console.info("getCurrentLocation callback_0003 err:  " + JSON.stringify(err));
                        expect(true).assertEqual(err != null);
                        console.info('getCurrentLocationCallback reject after')
                    } else {
                        console.info("getCurrentLocation callback_0003, result:  " + JSON.stringify(result));
                        expect(true).assertEqual(result != null);
                        resolve();
                    }
                });
            })
        }
        console.info('getCurrentLocationCallback  start');
Q
quanli 已提交
256 257 258 259 260 261 262
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info("getCurrentLocation callback_0003, result:  " + JSON.stringify(result));
            expect(true).assertEqual(result != null);
        }).catch(error => {
            console.info('getCurrentLocation callback_0003:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        })
Q
quanli 已提交
263
        done();
Q
q00313334 已提交
264 265 266
    })

    /**
Q
quanli 已提交
267
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0400
Q
quanli 已提交
268 269
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request in a specified scenario and set a car-sharing scenario.
Q
q00313334 已提交
270 271 272 273
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
274
    it('SUB_HSS_LocationSystem_SingleLoc_0400', 0, async function (done) {
Q
quanli 已提交
275 276 277 278 279 280 281 282 283
        let currentLocationRequest = { "priority": 0x200, "scenario": 0x303, "timeoutMs": 1000, "maxAccuracy": 10 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result004 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err004:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done();
Q
q00313334 已提交
284 285 286
    })

    /**
Q
quanli 已提交
287
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0500
Q
quanli 已提交
288 289
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request in a specified scenario and set the life service scenario..
Q
q00313334 已提交
290 291 292 293
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
294
    it('SUB_HSS_LocationSystem_SingleLoc_0500', 0, async function (done) {
Q
quanli 已提交
295 296 297 298 299 300 301 302 303
        let currentLocationRequest = { "priority": 0x200, "scenario": 0x304, "timeoutMs": 1000, "maxAccuracy": 0 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result005 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err005:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done();
Q
q00313334 已提交
304 305 306
    })

    /**
Q
quanli 已提交
307
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0600
Q
quanli 已提交
308 309 310
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request in a specified scenario
     *           and set the scenario with no power consumption.
Q
q00313334 已提交
311 312 313 314
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
315
    it('SUB_HSS_LocationSystem_SingleLoc_0600', 0, async function (done) {
Q
quanli 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
        let currentLocationRequest1 = { "priority": 0x200, "scenario": 0x305, "timeoutMs": 1000, "maxAccuracy": 10 };
        let currentLocationRequest2 = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 1000, "maxAccuracy": 10 };
        await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result0061 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err0061:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        })
        await geolocation.getCurrentLocation(currentLocationRequest2).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result0062 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation_0002 promise err0062:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done();
Q
q00313334 已提交
332 333 334
    })

    /**
Q
quanli 已提交
335
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0700
Q
quanli 已提交
336 337
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request with the parameter set to high-precision priority location request.
Q
q00313334 已提交
338 339 340 341
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
342
    it('SUB_HSS_LocationSystem_SingleLoc_0700', 0, async function (done) {
Q
quanli 已提交
343 344 345 346 347 348 349 350 351
        let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result007 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err007:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done();
Q
q00313334 已提交
352 353 354
    })

    /**
Q
quanli 已提交
355
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0800
Q
quanli 已提交
356 357
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request with parameters set to fast location and priority location request.
Q
q00313334 已提交
358 359 360 361
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
362
    it('SUB_HSS_LocationSystem_SingleLoc_0800', 0, async function (done) {
Q
quanli 已提交
363 364 365 366 367 368 369 370 371
        let currentLocationRequest = { "priority": 0x0203, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 10 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result010 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err010:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done();
Q
q00313334 已提交
372 373 374
    })

    /**
Q
quanli 已提交
375
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_0900
Q
quanli 已提交
376 377
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request with parameters set to low power consumption.
Q
q00313334 已提交
378 379 380 381
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
382
    it('SUB_HSS_LocationSystem_SingleLoc_0900', 0, async function (done) {
Q
quanli 已提交
383 384 385 386 387 388 389 390 391
        let currentLocationRequest = { "priority": 0x0202, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result009 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err009:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done();
Q
q00313334 已提交
392 393 394
    })

    /**
Q
quanli 已提交
395
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_1000
Q
quanli 已提交
396 397
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request and set the location reporting precision.
Q
q00313334 已提交
398 399 400 401
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
402
    it('SUB_HSS_LocationSystem_SingleLoc_1000', 0, async function (done) {
Q
quanli 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
        let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 5 };
        let currentLocationRequest1 = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 2 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result010 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err010:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        })
        await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result0102 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err0102:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        })
        done();
Q
q00313334 已提交
418 419 420
    })

    /**
Q
quanli 已提交
421
     * @tc.number SUB_HSS_LocationSystem_SingleLoc_1100
Q
quanli 已提交
422 423 424
     * @tc.name Test getCurrentLocation
     * @tc.desc Initiate a single location request for specific configuration
     *          and set the reporting precision of abnormal location.
Q
q00313334 已提交
425 426 427 428
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
429
    it('SUB_HSS_LocationSystem_SingleLoc_1100', 0, async function (done) {
Q
quanli 已提交
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
        let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": 0 };
        let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0300, "timeoutMs": 1000, "maxAccuracy": -1 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result011 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err011:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        })
        await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result0112 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err0112:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
Q
q00313334 已提交
445 446 447 448
        done();
    })

    /**
Q
quanli 已提交
449
    * @tc.number SUB_HSS_LocationSystem_SingleLoc_1200
Q
quanli 已提交
450 451 452 453 454 455
    * @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
    */
Q
quanli 已提交
456
    it('SUB_HSS_LocationSystem_SingleLoc_1200', 0, async function (done) {
Q
quanli 已提交
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
        let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 };
        let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0301, "timeoutMs": 1000, "maxAccuracy": 0 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result012 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err012:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        })
        await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result0122 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err0122:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
Q
q00313334 已提交
472 473 474 475
        done();
    })

    /**
Q
quanli 已提交
476
    * @tc.number SUB_HSS_LocationSystem_SingleLoc_1300
Q
quanli 已提交
477 478 479 480 481 482
    * @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
    */
Q
quanli 已提交
483
    it('SUB_HSS_LocationSystem_SingleLoc_1300', 0, async function (done) {
Q
quanli 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
        let currentLocationRequest = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": 0, "maxAccuracy": 0 };
        let currentLocationRequest1 = { "priority": 0x0201, "scenario": 0x0302, "timeoutMs": -1000, "maxAccuracy": 0 };
        await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result0131 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err0122:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
        });
        await geolocation.getCurrentLocation(currentLocationRequest1).then((result) => {
            console.info('[lbs_js] getCurrentLocation promise result0132 ' + JSON.stringify(result));
        }).catch(error => {
            console.info('getCurrentLocation promise err0122:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
            done();
        })
        done()
    })



    /**
Q
quanli 已提交
505
     * @tc.number SUB_HSS_SendCommand_0100
Q
quanli 已提交
506 507 508
     * @tc.name Test sendCommand
     * @tc.desc Test sendCommand api .
     * @tc.size MEDIUM
Q
q00313334 已提交
509
     * @tc.type Function
Q
quanli 已提交
510
     * @tc.level Level 2
Q
q00313334 已提交
511
     */
Q
quanli 已提交
512
    it('SUB_HSS_SendCommand_0100', 0, async function (done) {
Q
quanli 已提交
513
        let requestInfo = { 'scenairo': 0x301, 'command': "command_1" };
Q
quanli 已提交
514 515 516 517 518 519 520 521 522 523 524 525 526 527
        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();
Q
quanli 已提交
528 529 530
    })

    /**
Q
quanli 已提交
531
     * @tc.number SUB_HSS_SendCommand_0200
Q
quanli 已提交
532 533 534 535 536 537
     * @tc.name Test sendCommand
     * @tc.desc Test sendCommand1 api .
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
538
    it('SUB_HSS_SendCommand_0200', 0, async function (done) {
Q
quanli 已提交
539
        let requestInfo = { 'scenairo': 0x301, 'command': "command_1" };
Q
quanli 已提交
540 541 542 543 544 545 546 547 548 549
        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) {
Q
quanli 已提交
550 551
            console.info('sendcommand promise err:' + JSON.stringify(error));
            expect(true).assertEqual(JSON.stringify(error) != null);
Q
quanli 已提交
552 553
        }
        done();
Q
quanli 已提交
554 555 556
    })

    /**
Q
quanli 已提交
557
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0100
Q
quanli 已提交
558 559 560 561 562 563
     * @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
     */
Q
quanli 已提交
564
    it('SUB_HSS_LocationSystem_LocRequest_0100', 0, async function (done) {
Q
quanli 已提交
565 566 567 568 569 570 571 572 573
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5,
            "distanceInterval": 0, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
Q
q00313334 已提交
574 575 576 577
        done();
    })

    /**
Q
quanli 已提交
578
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0200
Q
quanli 已提交
579 580
     * @tc.name Test locationChange
     * @tc.desc Initiate a request for continuous positioning in a specified scenario and set a track tracing scenario.
Q
q00313334 已提交
581 582
     * @tc.size MEDIUM
     * @tc.type Function
Q
quanli 已提交
583
     * @tc.level Level 2
Q
q00313334 已提交
584
     */
Q
quanli 已提交
585
    it('SUB_HSS_LocationSystem_LocRequest_0200', 0, async function (done) {
Q
quanli 已提交
586 587 588 589 590 591 592 593 594
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x302, "timeInterval":1,
            "distanceInterval": 5, "maxAccuracy": 10};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
Q
q00313334 已提交
595 596 597 598
        done();
    })

    /**
Q
quanli 已提交
599
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0300
Q
quanli 已提交
600 601
     * @tc.name Test locationChange
     * @tc.desc Initiate a continuous location request in a specified scenario and set a car-sharing scenario.
Q
q00313334 已提交
602 603
     * @tc.size MEDIUM
     * @tc.type Function
Q
quanli 已提交
604
     * @tc.level Level 2
Q
q00313334 已提交
605
     */
Q
quanli 已提交
606
    it('SUB_HSS_LocationSystem_LocRequest_0300', 0, async function (done) {
Q
quanli 已提交
607 608 609 610 611 612 613 614 615
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":5,
            "distanceInterval": 5, "maxAccuracy": 10};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
Q
q00313334 已提交
616 617 618 619
        done();
    })

    /**
Q
quanli 已提交
620
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0400
Q
quanli 已提交
621 622
     * @tc.name Test locationChange
     * @tc.desc Initiate a continuous location request in a specified scenario and set a life service scenario.
Q
q00313334 已提交
623 624
     * @tc.size MEDIUM
     * @tc.type Function
Q
quanli 已提交
625
     * @tc.level Level 2
Q
q00313334 已提交
626
     */
Q
quanli 已提交
627
    it('SUB_HSS_LocationSystem_LocRequest_0400', 0, async function (done) {
Q
quanli 已提交
628 629 630 631 632 633 634 635 636
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x303, "timeInterval":1,
            "distanceInterval": 5, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
Q
q00313334 已提交
637 638 639 640
        done();
    })

    /**
Q
quanli 已提交
641
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0500
Q
quanli 已提交
642 643 644
     * @tc.name Test locationChange
     * @tc.desc Initiate a continuous location request in a specified scenario
     *          and set the scenario with no power consumption.
Q
q00313334 已提交
645 646 647 648
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
649
    it('SUB_HSS_LocationSystem_LocRequest_0500', 0, async function (done) {
Q
quanli 已提交
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x305, "timeInterval":1,
            "distanceInterval": 5, "maxAccuracy": 10};
        var locationChange1 = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        var locationChange2 = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange1);
        geolocation.on('locationChange', requestInfo, locationChange2);
        geolocation.off('locationChange', locationChange1);
        geolocation.off('locationChange', locationChange2);
        done();
    })

    /**
Q
quanli 已提交
669
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0700
Q
quanli 已提交
670 671 672 673 674 675 676
     * @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
     */
Q
quanli 已提交
677
    it('SUB_HSS_LocationSystem_LocRequest_0700', 0, async function (done) {
Q
quanli 已提交
678 679 680 681 682 683 684 685 686 687 688 689 690
        enableLocationSwitch();
        let requestInfo = {"priority":0x201, "scenario":0x300, "timeInterval":1,
            "distanceInterval": 5, "maxAccuracy": 10};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
        done();
    })

    /**
Q
quanli 已提交
691
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0800
Q
quanli 已提交
692 693 694 695 696 697 698
     * @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
     */
Q
quanli 已提交
699
    it('SUB_HSS_LocationSystem_LocRequest_0800', 0, async function (done) {
Q
quanli 已提交
700 701 702 703 704 705 706 707 708 709 710 711 712
        enableLocationSwitch();
        let requestInfo = {"priority":0x203, "scenario":0x300, "timeInterval":5,
            "distanceInterval": 5, "maxAccuracy": 10};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
        done();
    })

    /**
Q
quanli 已提交
713
     * @tc.number SUB_HSS_LocationSystem_LocRequest_0900
Q
quanli 已提交
714 715 716 717 718 719 720
     * @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
     */
Q
quanli 已提交
721
    it('SUB_HSS_LocationSystem_LocRequest_0900', 0, async function (done) {
Q
quanli 已提交
722 723 724 725 726 727 728 729 730 731 732 733 734
        enableLocationSwitch();
        let requestInfo = {"priority":0x202, "scenario":0x300, "timeInterval":1,
            "distanceInterval": 5, "maxAccuracy": 10}
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
        done();
    })

    /**
Q
quanli 已提交
735
     * @tc.number SUB_HSS_LocationSystem_LocRequest_1000
Q
quanli 已提交
736 737 738 739 740 741
     * @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
     */
Q
quanli 已提交
742
    it('SUB_HSS_LocationSystem_LocRequest_1000', 0, async function (done) {
Q
quanli 已提交
743 744 745 746 747 748 749 750 751 752 753 754 755
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":3,
            "distanceInterval": 0, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
        done();
    })

    /**
Q
quanli 已提交
756
     * @tc.number SUB_HSS_LocationSystem_LocRequest_1100
Q
quanli 已提交
757 758 759 760 761 762
     * @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
     */
Q
quanli 已提交
763
    it('SUB_HSS_LocationSystem_LocRequest_1100', 0, async function (done) {
Q
quanli 已提交
764
        enableLocationSwitch();
Q
q00313334 已提交
765
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":5,
Q
quanli 已提交
766 767 768 769
            "distanceInterval": 0, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
Q
q00313334 已提交
770
        };
Q
quanli 已提交
771 772
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
Q
q00313334 已提交
773 774 775 776
        done();
    })

    /**
Q
quanli 已提交
777
    * @tc.number SUB_HSS_LocationSystem_LocRequest_1200
Q
quanli 已提交
778 779 780 781 782 783
    * @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
    */
Q
quanli 已提交
784
    it('SUB_HSS_LocationSystem_LocRequest_1200', 0, async function (done) {
Q
quanli 已提交
785 786 787 788 789 790 791 792 793 794 795 796 797
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0,
            "distanceInterval": 0, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
        done();
    })

    /**
Q
quanli 已提交
798
    * @tc.number SUB_HSS_LocationSystem_LocRequest_1300
Q
quanli 已提交
799 800 801 802 803 804
    * @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
    */
Q
quanli 已提交
805
    it('SUB_HSS_LocationSystem_LocRequest_1300', 0, async function (done) {
Q
quanli 已提交
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
        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('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        var locationChange2 = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo1, locationChange1);
        geolocation.off('locationChange', locationChange1);
        geolocation.on('locationChange', requestInfo2, locationChange2);
        geolocation.off('locationChange', locationChange2);
        done();
    })

    /**
Q
quanli 已提交
827
    * @tc.number SUB_HSS_LocationSystem_LocRequest_1400
Q
quanli 已提交
828 829 830 831 832 833
    * @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
    */
Q
quanli 已提交
834
    it('SUB_HSS_LocationSystem_LocRequest_1400', 0, async function (done) {
Q
quanli 已提交
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
        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('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        var locationChange2 = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo1, locationChange1);
        geolocation.off('locationChange', locationChange1);
        geolocation.on('locationChange', requestInfo2, locationChange2);
        geolocation.off('locationChange', locationChange2);
        done();
    })

    /**
Q
quanli 已提交
856
    * @tc.number SUB_HSS_LocationSystem_LocRequest_1500
Q
quanli 已提交
857 858 859 860 861 862
    * @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
    */
Q
quanli 已提交
863
    it('SUB_HSS_LocationSystem_LocRequest_1500', 0, async function (done) {
Q
quanli 已提交
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
        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('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        var locationChange2 = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo1, locationChange1);
        geolocation.off('locationChange', locationChange1);
        geolocation.on('locationChange', requestInfo2, locationChange2);
        geolocation.off('locationChange', locationChange2);
        done();
    })

    /**
Q
quanli 已提交
885
     * @tc.number SUB_HSS_LocationSystem_LastLoc_0100
Q
quanli 已提交
886 887
     * @tc.name Test getLastLocation
     * @tc.desc Obtain the last location after a single location.
Q
q00313334 已提交
888 889 890 891
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
892
    it('SUB_HSS_LocationSystem_LastLoc_0100', 0, async function(done) {
Q
quanli 已提交
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0,
            "distanceInterval": 0, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
        await geolocation.getLastLocation().then((result) => {
            console.info('[lbs_js] getLastLocation promise result: ' + JSON.stringify(result));
            expect(true).assertEqual(JSON.stringify(result) != null);
            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: '
909
            + result.timeSinceBoot +'additions: ' + result.additions+' additionSize' + result.additionSize
Q
quanli 已提交
910
            + 'isFromMock' +result.isFromMock);
Q
quanli 已提交
911 912 913 914 915 916 917 918 919
        }).catch((error) => {
            console.info("[lbs_js] getLastLocation promise then error:" + JSON.stringify(error));
            console.info('[lbs_js] not support now');
            expect(true).assertEqual(JSON.stringify(error) != null);
        });
        done();
    })

    /**
Q
quanli 已提交
920
     * @tc.number SUB_HSS_LocationSystem_LastLoc_0200
Q
quanli 已提交
921 922 923 924 925 926
     * @tc.name Test getLastLocation
     * @tc.desc Obtain the last location after continuous positioning.
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
927
    it('SUB_HSS_LocationSystem_LastLoc_0200', 0, async function (done) {
Q
quanli 已提交
928 929 930 931 932 933 934 935 936
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0,
            "distanceInterval": 0, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
        };
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('locationChange', locationChange);
Q
quanli 已提交
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952

        function getLastLocationCallback(){
            return new Promise((resolve, reject)=>{
                geolocation.getLastLocation((err, data) => {
                    if (err) {
                        console.info('[LastLoc_0002]  getLastLocation callback err is : ' + JSON.stringify(err));
                        expect(true).assertEqual(err !=null);
                    } else {
                        console.info('[LastLoc_0002] getLastLocation callback result: ' + JSON.stringify(data));
                        expect(true).assertEqual(data !=null);
                    }
                    resolve();
                });
            })
        }
        await getLastLocationCallback();
Q
quanli 已提交
953 954 955 956
        done();
    })

    /**
Q
quanli 已提交
957
     * @tc.number SUB_HSS_LocationSystem_Gnss_0100
Q
quanli 已提交
958 959 960 961 962 963
     * @tc.name Test gnssStatusChange
     * @tc.desc Monitoring Satellite Information Reporting
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
964
    it('SUB_HSS_LocationSystem_Gnss_0100', 0, async function (done) {
Q
quanli 已提交
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
        await changedLocationMode();
        var gnssStatusCb = (satelliteStatusInfo) => {
            console.info('gnssStatusChange: ' + 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);
        }
        geolocation.on('gnssStatusChange', gnssStatusCb);
        enableLocationSwitch();
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0,
            "distanceInterval": 0, "maxAccuracy": 0};
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
Q
q00313334 已提交
981
        };
Q
quanli 已提交
982 983 984 985
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('gnssStatusChange', gnssStatusCb);
        geolocation.off('locationChange', locationChange);
        done();
Q
q00313334 已提交
986 987 988
    })

    /**
Q
quanli 已提交
989
     * @tc.number SUB_HSS_LocationSystem_Gnss_0200
Q
quanli 已提交
990 991
     * @tc.name Test nmeaMessageChange
     * @tc.desc Monitoring NMEA Information Reporting
Q
q00313334 已提交
992 993 994 995
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
996
    it('SUB_HSS_LocationSystem_Gnss_0200', 0, async function (done) {
Q
q00313334 已提交
997
        await changedLocationMode();
Q
quanli 已提交
998 999 1000 1001 1002 1003 1004 1005
        let requestInfo = {"priority":0x200, "scenario":0x301, "timeInterval":0,
            "distanceInterval": 0, "maxAccuracy": 0};
        var nmeaCb = (str) => {
            console.log('nmeaMessageChange: ' + str);
        }
        var locationChange = (location) => {
            console.log('locationChanger: data: ' + JSON.stringify(location));
            expect(true).assertEqual(locationChange !=null);
Q
q00313334 已提交
1006
        };
Q
quanli 已提交
1007 1008 1009 1010 1011 1012 1013 1014
        geolocation.on('nmeaMessageChange', nmeaCb);
        geolocation.on('locationChange', requestInfo, locationChange);
        geolocation.off('nmeaMessageChange', nmeaCb);
        geolocation.off('locationChange', locationChange);
        done();
    })

    /**
Q
quanli 已提交
1015
     * @tc.number SUB_HSS_LocationSystem_Batching_0100
Q
quanli 已提交
1016 1017 1018 1019 1020 1021
     * @tc.name Test cachedGnssLocationsReporting
     * @tc.desc Setting the Gnss Batching Reporting Interval
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
1022
    it('SUB_HSS_LocationSystem_Batching_0100', 0, async function (done) {
Q
quanli 已提交
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
        var cachedLocationsCb1 = (locations) => {
            console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
            expect(true).assertEqual(locations !=null);
        }
        var CachedGnssLoactionsRequest1 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false};
        geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest1, cachedLocationsCb1);
        geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb1);
        var cachedLocationsCb2 = (locations) => {
            console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
            expect(true).assertEqual(locations !=null);
        }
        var CachedGnssLoactionsRequest2 = {'reportingPeriodSec': 5, 'wakeUpCacheQueueFull': false};
        geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest2, cachedLocationsCb2);
        geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb1);
        done();
    })

    /**
Q
quanli 已提交
1041
     * @tc.number SUB_HSS_LocationSystem_Batching_0200
Q
quanli 已提交
1042 1043 1044 1045 1046 1047
     * @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
     */
Q
quanli 已提交
1048
    it('SUB_HSS_LocationSystem_Batching_0200', 0, async function (done) {
Q
quanli 已提交
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
        var cachedLocationsCb = (locations) => {
            console.log('cachedGnssLocationsReporting: 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};
        geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb);
        geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb);
        done();
    })

    /**
Q
quanli 已提交
1062
     * @tc.number SUB_HSS_LocationSystem_Batching_0300
Q
quanli 已提交
1063 1064 1065 1066 1067 1068
     * @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
     */
Q
quanli 已提交
1069
    it('SUB_HSS_LocationSystem_Batching_0300', 0, async function (done) {
Q
quanli 已提交
1070 1071 1072 1073 1074 1075 1076 1077 1078
        var cachedLocationsCb = (locations) => {
            console.log('cachedGnssLocationsReporting: 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};
        geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb);
        geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb);
Q
quanli 已提交
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
        function getCachedGnssLocationsSizeCallback(){
            return new Promise((resolve, reject)=>{
                geolocation.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();
Q
quanli 已提交
1094
        done();
Q
q00313334 已提交
1095 1096 1097
    })

    /**
Q
quanli 已提交
1098
     * @tc.number SUB_HSS_LocationSystem_Batching_0400
Q
quanli 已提交
1099 1100
     * @tc.name Test getCachedGnssLocationsSize
     * @tc.desc Obtains the number of GNSS data records in the batching process.
Q
q00313334 已提交
1101 1102 1103 1104
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
1105
    it('SUB_HSS_LocationSystem_Batching_0400', 0, async function (done) {
Q
quanli 已提交
1106 1107 1108 1109 1110 1111 1112 1113 1114
        var cachedLocationsCb = (locations) => {
            console.log('cachedGnssLocationsReporting: 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};
        geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb);
        geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb);
Q
q00313334 已提交
1115 1116 1117 1118 1119
        await geolocation.getCachedGnssLocationsSize().then( (result) => {
            console.info('[lbs_js] getCachedGnssLocationsSiz promise '+ JSON.stringify(result));
            expect(true).assertTrue(result != null);
            done();
        }).catch((error) => {
Q
quanli 已提交
1120
            console.info("[lbs_js] promise then error." + JSON.stringify(error));
Q
quanli 已提交
1121 1122
            expect(true).assertTrue(error != null);
            done();
Q
q00313334 已提交
1123 1124 1125 1126
        });
    })

    /**
Q
quanli 已提交
1127
     * @tc.number SUB_HSS_LocationSystem_Batching_0500
Q
quanli 已提交
1128 1129
     * @tc.name Test flushCachedGnssLocations
     * @tc.desc Obtains the GNSS data of the current batching.
Q
q00313334 已提交
1130 1131 1132 1133
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
1134
    it('SUB_HSS_LocationSystem_Batching_0500', 0, async function (done) {
Q
quanli 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143
        var cachedLocationsCb = (locations) => {
            console.log('cachedGnssLocationsReporting: 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};
        geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb);
        geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb);
Q
quanli 已提交
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
        function flushCachedGnssLocationsCallback(){
            return new Promise((resolve, reject)=>{
                geolocation.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();
Q
quanli 已提交
1159
        done();
Q
q00313334 已提交
1160 1161 1162
    })

    /**
Q
quanli 已提交
1163
     * @tc.number SUB_HSS_LocationSystem_Batching_0600
Q
quanli 已提交
1164 1165
     * @tc.name Test flushCachedGnssLocations
     * @tc.desc Obtain the GNSS data of the current batching.
Q
q00313334 已提交
1166 1167 1168 1169
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
Q
quanli 已提交
1170
    it('SUB_HSS_LocationSystem_Batching_0600', 0, async function (done) {
Q
quanli 已提交
1171 1172 1173 1174 1175 1176 1177 1178 1179
        var cachedLocationsCb = (locations) => {
            console.log('cachedGnssLocationsReporting: 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};
        geolocation.on('cachedGnssLocationsReporting', CachedGnssLoactionsRequest, cachedLocationsCb);
        geolocation.off('cachedGnssLocationsReporting',cachedLocationsCb);
Q
q00313334 已提交
1180 1181 1182 1183 1184
        await geolocation.flushCachedGnssLocations().then( (result) => {
            console.info('[lbs_js] flushCachedGnssLocations promise '+ JSON.stringify(result));
            expect(true).assertTrue(result);
            done();
        }).catch((error) => {
Q
quanli 已提交
1185
            console.info("[lbs_js] promise then error." + JSON.stringify(error));
Q
quanli 已提交
1186
            expect(true).assertTrue(error != null);
Q
q00313334 已提交
1187 1188
            done();
        });
Q
quanli 已提交
1189
        done();
Q
q00313334 已提交
1190
    })
1191

Q
quanli 已提交
1192
    /**
Q
quanli 已提交
1193
    * @tc.number SUB_HSS_LocationSystem_GeoFence_0100
Q
quanli 已提交
1194 1195 1196 1197 1198 1199
    * @tc.name Test fenceStatusChange
    * @tc.desc Gnss fence function test
    * @tc.size MEDIUM
    * @tc.type Function
    * @tc.level Level 1
    */
Q
quanli 已提交
1200
    it('SUB_HSS_LocationSystem_GeoFence_0100', 0, async function (done) {
Q
quanli 已提交
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
        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('wantAgent: ' + JSON.stringify(wantAgent));
            };
            geolocation.on('fenceStatusChange', geofenceRequest,
                (want) => {
                    if(err){
                        return console.info("fenceStatusChange on callback  err:  " + err);
                    }
                    console.info("fenceStatusChange callback, result:  " + JSON.stringify(want));
                    expect(true).assertEqual(want !=null);
                    done();
                });
            geolocation.off('fenceStatusChange',geofenceRequest,
                (want) => {
                    if(err){
                        return console.info("fenceStatusChange callback  err:  " + err);
                    }
                    console.info("off fenceStatusChange callback, result:  " + JSON.stringify(want));
                    expect(true).assertEqual(want !=null);
                });
        },1000);
        done();
    })
Q
quanli 已提交
1228

Q
quanli 已提交
1229
    /**
Q
quanli 已提交
1230
     * @tc.number SUB_HSS_LocationSystem_GeoFence_0500
Q
quanli 已提交
1231 1232 1233 1234 1235 1236
     * @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
     */
Q
quanli 已提交
1237
    it('SUB_HSS_LocationSystem_GeoFence_0500', 0, async function (done) {
Q
quanli 已提交
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
        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('wantAgent: ' + JSON.stringify(wantAgent));
            };
            geolocation.on('fenceStatusChange', geofenceRequest,
                (want) => {
                    if(err){
                        return console.info("fenceStatusChange on callback  err:  " + err);
                    }
                    console.info("fenceStatusChange callback, result:  " + JSON.stringify(want));
                    expect(true).assertEqual(want !=null);
                    done();
                });
            geolocation.off('fenceStatusChange',geofenceRequest,
                (want) => {
                    if(err){
                        return console.info("fenceStatusChange callback  err:  " + err);
                    }
                    console.info("off fenceStatusChange callback, result:  " + JSON.stringify(want));
                    expect(true).assertEqual(want !=null);
                });
        },1000);
        done();
    })
Q
quanli 已提交
1265 1266 1267 1268

    })
}

Q
quanli 已提交
1269

Q
quanli 已提交
1270