提交 b4ee85cf 编写于 作者: Q quanli

quanli1@huawei.com

Signed-off-by: Nquanli <quanli1@huawei.com>
上级 15d905f0
......@@ -17,6 +17,7 @@ import geolocation from '@ohos.geolocation';
import { LocationEventListener } from '@ohos.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import osaccount from '@ohos.account.osAccount'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 ,
TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303,
......@@ -33,22 +34,29 @@ function sleep(ms) {
}
async function changedLocationMode(){
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + result);
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
if(!result){
await geolocation.requestEnableLocation().then(async(result) => {
await sleep(3000);
console.info('[lbs_js] test requestEnableLocation promise result: ' + result);
console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
expect(result).assertTrue();
}).catch((error) => {
console.info("[lbs_js] promise then error." + error.message);
console.info("[lbs_js] promise then error." + JSON.stringify(error));
expect().assertFail();
});
}
})
});
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
});
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100);
let osAccountManager = osaccount.getAccountManager();
console.debug("=== getAccountManager finish");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("LocalId is :" + localId);
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
......@@ -56,14 +64,14 @@ async function applyPermission() {
let permissionName1 = 'ohos.permission.LOCATION';
let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
......@@ -71,29 +79,19 @@ async function applyPermission() {
}
describe('geolocationTest_geo1', function () {
let data = {
title: "",
locationChange: null,
locatlocationServiceState: null
}
console.log('#start AccessTokenTests#');
beforeAll(async function (done) {
console.info('beforeAll case');
await applyPermission();
setTimeout(function () {
this.locationChange = (err, location) => {
console.log(' locationChange: ' + err + " data: " + JSON.stringify(location));
};
this.locationServiceState = (err, state) => {
console.log('locationServiceState: ' + err + " data: " + state);
};
done();
},3000);
console.info('beforeAll case');
})
beforeEach(async function () {
await changedLocationMode();
beforeEach(async function (done) {
console.info('beforeEach case');
await changedLocationMode();
done();
})
afterEach(function () {
})
......@@ -109,11 +107,13 @@ describe('geolocationTest_geo1', function () {
it('SUB_HSS_LocationSystem_Geo_0001', 0, async function (done) {
geolocation.isGeoServiceAvailable(async(err, data) => {
if (err) {
console.info('[lbs_js] getGeoServiceState err is : ' + err );
console.info('[lbs_js] getGeoServiceState err is : ' + JSON.stringify(err) );
}else {
console.info('[lbs_js] isGeoServiceAvailable callback result: ' + data);
expect(data).assertTrue();
console.info('[lbs_js] isGeoServiceAvailable callback result: ' + JSON.stringify(data));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(data)!=null);
done();
}
done()
})
......@@ -129,10 +129,11 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_Geo_0002', 0, async function (done) {
await geolocation.isGeoServiceAvailable().then( (result) => {
console.info('[lbs_js] isGeoServiceAvailable1 promise result: ' + result);
expect(result).assertTrue();
console.info('[lbs_js] isGeoServiceAvailable1 promise result: ' + JSON.stringify(result));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(result)!=null);
}).catch((error) => {
console.info("[lbs_js] promise then error." + error.message);
console.info("[lbs_js] promise then error." + JSON.stringify(error));
expect().assertFail();
});
done();
......@@ -151,7 +152,7 @@ describe('geolocationTest_geo1', function () {
let promise = new Promise((resolve,reject) => {
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) {
console.info('[lbs_js] getAddressesFromLocation callback err is : ' + err);
console.info('[lbs_js] getAddressesFromLocation callback err is : ' + JSON.stringify(err));
}else {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) !=null);
......@@ -174,15 +175,21 @@ describe('geolocationTest_geo1', function () {
let reverseGeocodeRequest = {"latitude": 31.265496, "longitude": 121.62771, "maxItems": 1};
await geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.info('[lbs_js] getAddressesFromLocation04 promise: ' + JSON.stringify(data));
console.info('addressUrl: ' + data[0].addressUrl + data[0].administrativeArea + data[0].countryCode
+ data[0].countryName+ data[0].descriptions+ data[0].descriptionsSize +data[0].latitude
+ data[0].locale+ data[0].locality+ data[0].longitude+ data[0].phoneNumber+ data[0].placeName
+ data[0].postalCode+ data[0].premises+ data[0].roadName+ data[0].subAdministrativeArea
+ data[0].subLocality+ data[0].subRoadName);
console.info('addressUrl: ' + JSON.stringify(data)[0].addressUrl
+ JSON.stringify(data)[0].administrativeArea + JSON.stringify(data)[0].countryCode
+ JSON.stringify(data)[0].countryName+ JSON.stringify(data)[0].descriptions
+ JSON.stringify(data)[0].descriptionsSize +data[0].latitude
+ JSON.stringify(data)[0].locale+ JSON.stringify(data)[0].locality
+ JSON.stringify(data)[0].longitude+ JSON.stringify(data)[0].phoneNumber
+ JSON.stringify(data)[0].placeName
+ JSON.stringify(data)[0].postalCode+ JSON.stringify(data)[0].premises
+ JSON.stringify(data)[0].roadName+ JSON.stringify(data)[0].subAdministrativeArea
+ JSON.stringify(data)[0].subLocality+ JSON.stringify(data)[0].subRoadName);
done();
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation promise then error." + error.message);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocation promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
done();
});
})
......@@ -202,8 +209,9 @@ describe('geolocationTest_geo1', function () {
expect(true).assertEqual((JSON.stringify(data)) !=null);
done();
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocation promise then error." + error.message);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocation promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
done();
});
})
......@@ -222,15 +230,16 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] getAddressesFromLocation0601 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) !=null);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + error.message);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocation0601 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let reverseGeocodeRequest2 = {"latitude": 90.1, "longitude": 121.62771, "maxItems": 1};
await geolocation.getAddressesFromLocation(reverseGeocodeRequest2).then((data) => {
console.info('[lbs_js] getAddressesFromLocation promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0602 promise then error." + error.message);
console.info("[lbs_js] getAddressesFromLocation0602 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
let reverseGeocodeRequest3 = {"latitude": -90, "longitude": 121.62771, "maxItems": 1};
......@@ -238,15 +247,16 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] getAddressesFromLocation0603 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) !=null);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0603 promise then error." + error.message);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocation0603 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let reverseGeocodeRequest4 = {"latitude": -90.1, "longitude": 121.62771, "maxItems": 1};
await geolocation.getAddressesFromLocation(reverseGeocodeRequest4).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0604 promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0604 promise then error." + error);
console.info("[lbs_js] getAddressesFromLocation0604 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
done()
......@@ -266,15 +276,16 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] getAddressesFromLocation0701 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) !=null);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0701 promise then error." + error.message);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocation0701 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let reverseGeocodeRequest1 = {"latitude": 31.265496, "longitude": -180.1, "maxItems": 1};
await geolocation.getAddressesFromLocation(reverseGeocodeRequest1).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0702 promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0702 promise then error." + error.message);
console.info("[lbs_js] getAddressesFromLocation0702 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
let reverseGeocodeRequest2 = {"latitude": 31.265496, "longitude": 180, "maxItems": 1};
......@@ -282,15 +293,16 @@ describe('geolocationTest_geo1', function () {
console.info('[lbs_js] getAddressesFromLocation0703 promise: ' + JSON.stringify(data));
expect(true).assertEqual((JSON.stringify(data)) !=null);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0703 promise then error." + error.message);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocation0703 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let reverseGeocodeRequest3 = {"latitude": 31.265496, "longitude": 180.1, "maxItems": 1};
await geolocation.getAddressesFromLocation(reverseGeocodeRequest3).then((data) => {
console.info('[lbs_js] getAddressesFromLocation0704 promise: ' + JSON.stringify(data));
expect(data.length).assertEqual(0);
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation0704 promise then error." + error.message);
console.info("[lbs_js] getAddressesFromLocation0704 promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
done()
......@@ -311,28 +323,28 @@ describe('geolocationTest_geo1', function () {
if(err){
switch(err){
case 101:
console.info("INPUT_PARAMS_ERROR: "+ err);
console.info("INPUT_PARAMS_ERROR: "+ JSON.stringify(err));
break;
case 102:
console.info("REVERSE_GEOCODE_ERROR: "+ err);
console.info("REVERSE_GEOCODE_ERROR: "+ JSON.stringify(err));
break;
case 103:
console.info("GEOCODE_ERROR: "+ err);
console.info("GEOCODE_ERROR: "+ JSON.stringify(err));
break;
case 104:
console.info("LOCATOR_ERROR: "+ err);
console.info("LOCATOR_ERROR: "+ JSON.stringify(err));
break;
case 105:
console.info("LOCATION_SWITCH_ERROR: "+ err);
console.info("LOCATION_SWITCH_ERROR: "+ JSON.stringify(err));
break;
case 106:
console.info("LAST_KNOWN_LOCATION_ERROR: "+ err);
console.info("LAST_KNOWN_LOCATION_ERROR: "+ JSON.stringify(err));
break;
case 107:
console.info("LOCATION_REQUEST_TIMEOUT_ERROR: "+ err);
console.info("LOCATION_REQUEST_TIMEOUT_ERROR: "+ JSON.stringify(err));
break;
default:
console.info('[lbs_js] getAddressesFromLocationName callback err is : ' + err);
console.info('[lbs_js] getAddressesFromLocationName callback err is : ' + JSON.stringify(err));
}
}else {
console.info("[lbs_js] getAddressesFromLocationName08 callback data is: " + JSON.stringify(data));
......@@ -356,7 +368,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName09 promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName09 promise then error." + JSON.stringify(error));
expect().assertFail();
});
done();
......@@ -376,8 +388,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation m callback data is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName m promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocationName m promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
done();
})
......@@ -396,16 +409,18 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let geocodeRequest1 = {"description": null, "maxItems": 1};
await geolocation.getAddressesFromLocationName(geocodeRequest1).then((result) => {
console.info("[lbs_js] getAddressesFromLocation promise data is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
done();
})
......@@ -425,8 +440,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
done();
})
......@@ -446,7 +462,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result));
expect(result.length==0).assertTrue();
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
let geocodeRequest1 = {"description": null, "maxItems": 1, "minLatitude":331.3082812847 ,
......@@ -455,7 +471,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result));
expect(result.length==0).assertTrue();
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
done();
......@@ -476,8 +492,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result));
expect(result.length>=0).assertTrue();
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
done()
})
......@@ -497,8 +514,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js] getAddressesFromLocation callback data is: " + JSON.stringify(result));
expect(result.length>=0).assertTrue();
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
done()
})
......@@ -518,8 +536,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise1: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect(true).assertEqual((JSON.stringify(error)) ==null);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let geocodeRequest2 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":90 ,
"minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943};
......@@ -527,8 +546,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise2: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect(true).assertEqual((JSON.stringify(error)) ==null);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let geocodeRequest3 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":-90.1 ,
"minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943};
......@@ -536,16 +556,17 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise3: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) ==null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
let geocodeRequest4 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":90.1 ,
"minLongitude":121.5782001832,"maxLatitude":31.1537977881,"maxLongitude":121.8026736943};
await geolocation.getAddressesFromLocationName(geocodeRequest4).then((result) => {
console.info("[lbs_js]getAddressesFromLocation promise4: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) ==null);
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
let geocodeRequest5 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 ,
......@@ -554,8 +575,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise5: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect(true).assertEqual((JSON.stringify(error)) ==null);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let geocodeRequest6 = {"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 ,
"minLongitude":121.5782001832,"maxLatitude":90,"maxLongitude":121.8026736943};
......@@ -563,8 +585,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise6: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect(true).assertEqual((JSON.stringify(error)) ==null);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let geocodeRequest7 ={"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 ,
"minLongitude":121.5782001832,"maxLatitude":-90.1,"maxLongitude":121.8026736943};
......@@ -572,7 +595,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise7: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) ==null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
let geocodeRequest8 ={"description": "上海金穗路1800号", "maxItems": 1, "minLatitude":31.3082812847 ,
......@@ -581,7 +604,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise8: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) ==null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(true).assertEqual((JSON.stringify(error)) !=null);
});
done()
......@@ -602,8 +625,9 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise1: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
expect(error==null).assertTrue();
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
let geocodeRequest2 ={"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 ,
"minLongitude":180,"maxLatitude":39.95,"maxLongitude":116.45};
......@@ -611,7 +635,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise2: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(error.length!=0).assertTrue();
});
let geocodeRequest3 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 ,
......@@ -620,7 +644,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise3: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(error.length!=0).assertTrue();
});
let geocodeRequest4 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 ,
......@@ -629,7 +653,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise4: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(error.length!=0).assertTrue();
});
let geocodeRequest5 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 ,
......@@ -638,7 +662,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise5: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(error.length!=0).assertTrue();
});
let geocodeRequest6 = {"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 ,
......@@ -647,7 +671,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise6: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(error.length!=0).assertTrue();
});
let geocodeRequest7 ={"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 ,
......@@ -656,7 +680,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise7: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(error.length!=0).assertTrue();
});
let geocodeRequest8 ={"description": "北京天安门", "maxItems": 1, "minLatitude":39.85 ,
......@@ -665,7 +689,7 @@ describe('geolocationTest_geo1', function () {
console.info("[lbs_js]getAddressesFromLocation promise8: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getAddressesFromLocationName promise then error." + error);
console.info("[lbs_js] getAddressesFromLocationName promise then error." + JSON.stringify(error));
expect(error.length!=0).assertTrue();
});
done()
......@@ -682,10 +706,10 @@ describe('geolocationTest_geo1', function () {
it('SUB_HSS_LocationSystem_LocSwitch_0001', 0, async function (done) {
geolocation.isLocationEnabled(async(err, data) => {
if (err) {
console.info('[lbs_js] getLocationSwitchState err is : ' + err );
console.info('[lbs_js] getLocationSwitchState err is : ' + JSON.stringify(err) );
}else {
console.info('[lbs_js] getLocationSwitchState callback data1: ' + data);
console.info('[lbs_js] getLocationSwitchState callback data1: ' + JSON.stringify(data));
expect(data).assertTrue();
}
done()
......@@ -702,7 +726,7 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_LocSwitch_0002', 0, async function (done) {
await geolocation.isLocationEnabled().then((result) => {
console.info('[lbs_js] getLocationSwitchStateLocSwitch_00021 result: ' + result);
console.info('[lbs_js] getLocationSwitchStateLocSwitch_00021 result: ' + JSON.stringify(result));
expect(result).assertTrue();
}).catch((error) => {
expect().assertFail();
......@@ -721,10 +745,10 @@ describe('geolocationTest_geo1', function () {
it('SUB_HSS_LocationSystem_LocSwitch_0003', 0, async function (done) {
geolocation.isLocationEnabled(async(err, data) => {
if (err) {
console.info('[lbs_js] getLocationSwitchState callback err is : ' + err );
console.info('[lbs_js] getLocationSwitchState callback err is : ' + JSON.stringify(err) );
}else {
console.info("[lbs_js] getLocationSwitchState callback data: " + data);
console.info("[lbs_js] getLocationSwitchState callback data: " + JSON.stringify(data));
expect(data).assertTrue();
}
done()
......@@ -741,7 +765,7 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_LocSwitch_0004', 0, async function (done) {
await geolocation.isLocationEnabled().then((result1) => {
console.info('[lbs_js] getLocationSwitchStateLocSwitch_0004 result: ' + result1);
console.info('[lbs_js] getLocationSwitchStateLocSwitch_0004 result: ' + JSON.stringify(result1));
expect(result1).assertTrue();
}).catch((error) => {
expect().assertFail();
......@@ -760,27 +784,22 @@ describe('geolocationTest_geo1', function () {
it('SUB_HSS_LocationSystem_LocSwitch_0005', 0, async function (done) {
geolocation.on('locationServiceState',
(result) => {
if(err){
return console.info("locationServiceState on callback err: " + err);
}
console.info("locationServiceState on result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
done();
});
geolocation.requestEnableLocation((err, data) => {
if (err) {
console.info('[lbs_js] requestEnableLocation callback err is : ' + err );
console.info('[lbs_js] requestEnableLocation callback err is : ' + JSON.stringify(err) );
}else {
console.info("[lbs_js] requestEnableLocation callback data: " + data);
console.info("[lbs_js] requestEnableLocation callback data: " + JSON.stringify(data));
expect(data).assertTrue();
}
done()
});
geolocation.off('locationServiceState',
(result) => {
if(err){
return console.info("locationServiceState off callback err: " + err);
}
console.info("locationServiceState off callback, result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
done();
......@@ -799,14 +818,14 @@ describe('geolocationTest_geo1', function () {
let currentLocationRequest = { "priority": 0x200, "scenario": 0x301, "timeoutMs": 10, "maxAccuracy": 0 };
geolocation.requestEnableLocation(async(err, data) => {
if (err) {
console.info('[lbs_js] requestEnableLocation callback err is : ' + err );
console.info('[lbs_js] requestEnableLocation callback err is : ' + JSON.stringify(err) );
}
console.info("[lbs_js] requestEnableLocation callback data: " + data);
console.info("[lbs_js] requestEnableLocation callback data: " + JSON.stringify(data));
expect(data).assertTrue();
geolocation.getCurrentLocation(currentLocationRequest,
async(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -850,7 +869,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
expect(true).assertEqual(resultLength >= 0);
......@@ -871,7 +890,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -893,7 +912,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -916,11 +935,11 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest1,
async(err, result) => {
if (err){
console.info("getCurrentLocation callback1 err: " + err)
console.info("getCurrentLocation callback1 err: " + JSON.stringify(err))
geolocation.getCurrentLocation(currentLocationRequest2,
async(err, result) => {
if (err){
return console.info("getCurrentLocation callback2 err: " + err)
return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result2: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -949,7 +968,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -972,7 +991,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -995,7 +1014,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1018,7 +1037,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1041,7 +1060,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1064,7 +1083,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1087,7 +1106,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1110,7 +1129,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1133,7 +1152,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1157,11 +1176,11 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest1,
async(err, result) => {
if (err){
console.info("getCurrentLocation callback1 err: " + err)
console.info("getCurrentLocation callback1 err: " + JSON.stringify(err))
geolocation.getCurrentLocation(currentLocationRequest2,
async(err, result) => {
if (err){
return console.info("getCurrentLocation callback2 err: " + err)
return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result2: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1190,7 +1209,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1213,7 +1232,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1236,7 +1255,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1259,7 +1278,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1282,7 +1301,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1306,11 +1325,11 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest1,
async(err, result) => {
if (err){
console.info("getCurrentLocation callback1 err: " + err)
console.info("getCurrentLocation callback1 err: " + JSON.stringify(err))
geolocation.getCurrentLocation(currentLocationRequest2,
async(err, result) => {
if (err){
return console.info("getCurrentLocation callback2 err: " + err)
return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result2: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1339,7 +1358,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1362,7 +1381,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1385,7 +1404,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1408,7 +1427,7 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest,
(err, result) => {
if (err){
return console.info("getCurrentLocation callback err: " + err)
return console.info("getCurrentLocation callback err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1432,11 +1451,11 @@ describe('geolocationTest_geo1', function () {
geolocation.getCurrentLocation(currentLocationRequest1,
async(err, result) => {
if (err){
console.info("getCurrentLocation callback1 err: " + err)
console.info("getCurrentLocation callback1 err: " + JSON.stringify(err))
geolocation.getCurrentLocation(currentLocationRequest2,
async(err, result) => {
if (err){
return console.info("getCurrentLocation callback2 err: " + err)
return console.info("getCurrentLocation callback2 err: " + JSON.stringify(err))
}else{
console.info("getCurrentLocation callback, result2: " + JSON.stringify(result));
let resultLength = Object.keys(result).length;
......@@ -1466,9 +1485,9 @@ describe('geolocationTest_geo1', function () {
it('SUB_HSS_LocationSystem_LastLocation_0001', 0, async function (done) {
geolocation.getLastLocation(async(err, data) => {
if (err) {
console.info('[lbs_js] getLastLocation callback err is : ' + err );
console.info('[lbs_js] getLastLocation callback err is : ' + JSON.stringify(err) );
}else {
console.info('[lbs_js] getLastLocation callback result: ' + data);
console.info('[lbs_js] getLastLocation callback result: ' + JSON.stringify(data));
expect(data).assertTrue();
}
done()
......@@ -1484,15 +1503,14 @@ describe('geolocationTest_geo1', function () {
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_LastLocation_0002', 0, async function (done) {
setTimeout(async ()=>{
await geolocation.getLastLocation().then((result) => {
console.info('[lbs_js] getLastLocation promise result: ' + result);
console.info('[lbs_js] getLastLocation promise result: ' + JSON.stringify(result));
expect(result).assertTrue();
}).catch((error) => {
console.info('[lbs_js] getLastLocation promise then err: ' + result);
expect().assertFail();
console.info('[lbs_js] getLastLocation promise then err: ' + JSON.stringify(result));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
},2000);
done();
})
......@@ -1506,15 +1524,14 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_SingleLoc_0028', 0, async function (done) {
let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0300, "timeoutMs": 10, "maxAccuracy": 0 };
setTimeout(async ()=>{
await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
console.info("[lbs_js] getCurrentLocation promise data is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getCurrentLocation promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
},2000);
done();
})
......@@ -1528,15 +1545,14 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_SingleLoc_0029', 0, async function (done) {
let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0301, "timeoutMs": 10, "maxAccuracy": 0 };
setTimeout(async ()=>{
await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getCurrentLocation promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
},2000);
done();
})
......@@ -1550,15 +1566,14 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_SingleLoc_0030', 0, async function (done) {
let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0302, "timeoutMs": 10, "maxAccuracy": 0 };
setTimeout(async ()=>{
await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getCurrentLocation promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
},2000);
done();
})
......@@ -1571,17 +1586,15 @@ describe('geolocationTest_geo1', function () {
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_SingleLoc_0031', 0, async function (done) {
let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0303, "timeoutMs": 10, "maxAccuracy": 0 };
setTimeout(async ()=>{
await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getCurrentLocation promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
},2000);
done();
})
......@@ -1595,18 +1608,59 @@ describe('geolocationTest_geo1', function () {
*/
it('SUB_HSS_LocationSystem_SingleLoc_0032', 0, async function (done) {
let currentLocationRequest = { "priority": 0x0200, "scenario": 0x0304, "timeoutMs": 10, "maxAccuracy": 0 };
setTimeout(async ()=>{
await geolocation.getCurrentLocation(currentLocationRequest).then((result) => {
console.info("[lbs_js] getCurrentLocation promise result is: " + JSON.stringify(result));
expect(true).assertEqual((JSON.stringify(result)) !=null);
}).catch((error) => {
console.info("[lbs_js] getCurrentLocation promise then error." + error);
expect().assertFail();
console.info("[lbs_js] getCurrentLocation promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(true).assertEqual(JSON.stringify(error)!=null);
});
done();
})
/**
* @tc.number SingleLoc_0032
* @tc.name SUB_HSS_LocationSystem_SingleLoc_0032
* @tc.desc Test getCurrentLocation api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_HSS_SendCommand_callback', 0, async function (done) {
let requestInfo = {'scenairo':0x301,'command':"command_1"};
await geolocation.sendCommand(requestInfo,(err,result) =>{
if(err){
console.info('sendcommand callback err:'+err);
expect(true).assertEqual(JSON.stringify(err)!=null);
done();
}
console.info('sendcommand callback result:' +result);
});
},2000);
})
/**
* @tc.number SingleLoc_0032
* @tc.name SUB_HSS_LocationSystem_SingleLoc_0032
* @tc.desc Test getCurrentLocation api .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 2
*/
it('SUB_HSS_SendCommand_promise', 0, async function (done) {
let requestInfo = {'scenairo':0x301,'command':"command_1"};
await geolocation.sendCommand(requestInfo).then((result) =>{
console.info('sendCommand promise result:'+result);
done();
}).catch(error=>{
console.info('sendcommand promise err:'+err);
expect(true).assertEqual(JSON.stringify(err)!=null);
done();
})
})
})
......
......@@ -16,30 +16,38 @@ import geolocation from '@ohos.geolocation';
import geolocations from '@system.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import osaccount from '@ohos.account.osAccount'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function changedLocationMode(){
async function changedLocationMode(){
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + result);
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
if(!result){
await geolocation.requestEnableLocation().then(async(result) => {
await sleep(3000);
console.info('[lbs_js] test requestEnableLocation promise result: ' + result);
console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
expect(result).assertTrue();
}).catch((error) => {
console.info("[lbs_js] promise then error." + error.message);
console.info("[lbs_js] promise then error." + JSON.stringify(error));
expect().assertFail();
});
}
})
});
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
});
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100);
let osAccountManager = osaccount.getAccountManager();
console.debug("=== getAccountManager finish");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("LocalId is :" + localId);
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
......@@ -47,21 +55,21 @@ async function applyPermission() {
let permissionName1 = 'ohos.permission.LOCATION';
let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
describe('geolocationTest', function () {
describe('geolocationTest_geo2', function () {
beforeAll(async function (done) {
console.info('beforeAll case');
await applyPermission();
......@@ -192,17 +200,12 @@ describe('geolocationTest', function () {
* @tc.level Level 2
*/
it('SUB_HSS_LocationSystem_0005', 0, async function (done) {
geolocation.unsubscribe(
(result) => {
if(err){
return console.info("unsubscribe err: " + err);
}
console.info("unsubscribe result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
});
geolocation.unsubscribe();
console.info("[lbs_js] unsubscribe called")
done();
})
})
......@@ -17,6 +17,7 @@ import geolocation from '@ohos.geolocation';
import { LocationEventListener } from '@ohos.geolocation';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import osaccount from '@ohos.account.osAccount'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
let LocationRequestScenario = {UNSET : 0x300 ,NAVIGATION : 0x301 ,
TRAJECTORY_TRACKING : 0x302 ,CAR_HAILING : 0x303,
......@@ -34,22 +35,29 @@ function sleep(ms) {
async function changedLocationMode(){
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + result);
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
if(!result){
await geolocation.requestEnableLocation().then(async(result) => {
await sleep(3000);
console.info('[lbs_js] test requestEnableLocation promise result:' + result);
console.info('[lbs_js] test requestEnableLocation promise result: ' + JSON.stringify(result));
expect(result).assertTrue();
}).catch((error) => {
console.info("[lbs_js] promise then error." + error.message);
console.info("[lbs_js] promise then error." + JSON.stringify(error));
expect().assertFail();
});
}
})
});
await geolocation.isLocationEnabled().then(async(result) => {
console.info('[lbs_js] getLocationSwitchState result: ' + JSON.stringify(result));
});
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, 100);
let osAccountManager = osaccount.getAccountManager();
console.debug("=== getAccountManager finish");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("LocalId is :" + localId);
let appInfo = await bundle.getApplicationInfo('ohos.acts.location.geolocation.function', 0, localId);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
......@@ -57,21 +65,21 @@ async function applyPermission() {
let permissionName1 = 'ohos.permission.LOCATION';
let permissionName2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
console.info('[permission] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
describe('geolocationTest', function () {
describe('geolocationTest_geo3', function () {
let data = {
title: "",
locationChange: null,
......@@ -1037,6 +1045,8 @@ describe('geolocationTest', function () {
geolocation.getCachedGnssLocationsSize((err, data) => {
if (err) {
console.info('[lbs_js] getCachedGnssLocationsSize callback err is : ' + err);
expect(true).assertTrue(err != null);
done();
}else {
console.info("[lbs_js] getCachedGnssLocationsSize callback data is: " + JSON.stringify(data));
expect(true).assertTrue(data != null);
......@@ -1086,7 +1096,8 @@ describe('geolocationTest', function () {
done();
}).catch((error) => {
console.info("[lbs_js] promise then error." + error.message);
expect().assertFail();
expect(true).assertTrue(error != null);
done();
done();
});
})
......@@ -1106,6 +1117,8 @@ describe('geolocationTest', function () {
(result) => {
if(err){
return console.info("oncachedGnssLocationsReporting callback err: " + err);
expect(true).assertTrue(err != null);
done();
}
console.info("cachedGnssLocationsReporting result: " + JSON.stringify(result));
expect(true).assertEqual(result !=null);
......@@ -1128,6 +1141,8 @@ describe('geolocationTest', function () {
geolocation.flushCachedGnssLocations((err, data) => {
if (err) {
console.info('[lbs_js] flushCachedGnssLocations callback err is : ' + err);
expect(true).assertTrue(err != null);
done();
}else {
console.info("[lbs_js] flushCachedGnssLocations callback data is: " + JSON.stringify(data));
expect(true).assertTrue(data);
......@@ -1177,7 +1192,7 @@ describe('geolocationTest', function () {
done();
}).catch((error) => {
console.info("[lbs_js] promise then error." + error.message);
expect().assertFail();
expect(true).assertTrue(error != null);
done();
});
})
......@@ -1185,3 +1200,4 @@ describe('geolocationTest', function () {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册