• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "location_common_test.h"
17 
18 #include "string_ex.h"
19 
20 #include "message_parcel.h"
21 #include "ipc_skeleton.h"
22 #include "common_event_subscriber.h"
23 #include "common_event_manager.h"
24 #include "common_event_support.h"
25 #include "want.h"
26 #include "want_agent.h"
27 
28 #include "app_identity.h"
29 #include "common_hisysevent.h"
30 #include "constant_definition.h"
31 #include "geo_address.h"
32 #include "geo_coding_mock_info.h"
33 #include "geofence_state.h"
34 #include "location.h"
35 #include "location_log.h"
36 #include "request_config.h"
37 #include "satellite_status.h"
38 #include "permission_status_change_cb.h"
39 #include "common_utils.h"
40 #include "locator_event_subscriber.h"
41 #include "country_code_manager.h"
42 
43 using namespace testing::ext;
44 namespace OHOS {
45 namespace Location {
46 using Want = OHOS::AAFwk::Want;
47 const double MOCK_LATITUDE = 99.0;
48 const double MOCK_LONGITUDE = 100.0;
49 const double VERIFY_LOCATION_LATITUDE = 12.0;
50 const double VERIFY_LOCATION_LONGITUDE = 13.0;
51 const double VERIFY_LOCATION_ALTITUDE = 14.0;
52 const double VERIFY_LOCATION_ACCURACY = 1000.0;
53 const double VERIFY_LOCATION_SPEED = 10.0;
54 const double VERIFY_LOCATION_DIRECTION = 90.0;
55 const double VERIFY_LOCATION_TIME = 1000000000;
56 const double VERIFY_LOCATION_TIMESINCEBOOT = 1000000000;
57 const double VERIFY_LOCATION_FLOOR_ACC = 1000.0;
SetUp()58 void LocationCommonTest::SetUp()
59 {
60 }
61 
TearDown()62 void LocationCommonTest::TearDown()
63 {
64 }
65 
SetGeoAddress(std::unique_ptr<GeoAddress> & geoAddress)66 void LocationCommonTest::SetGeoAddress(std::unique_ptr<GeoAddress>& geoAddress)
67 {
68     MessageParcel parcel;
69     parcel.WriteString16(u"localeLanguage");
70     parcel.WriteString16(u"localeCountry");
71     parcel.WriteInt32(1); // size
72     parcel.WriteInt32(0); // line
73     parcel.WriteString16(u"line");
74     parcel.WriteString16(u"placeName");
75     parcel.WriteString16(u"administrativeArea");
76     parcel.WriteString16(u"subAdministrativeArea");
77     parcel.WriteString16(u"locality");
78     parcel.WriteString16(u"subLocality");
79     parcel.WriteString16(u"roadName");
80     parcel.WriteString16(u"subRoadName");
81     parcel.WriteString16(u"premises");
82     parcel.WriteString16(u"postalCode");
83     parcel.WriteString16(u"countryCode");
84     parcel.WriteString16(u"countryName");
85     parcel.WriteInt32(1); // hasLatitude
86     parcel.WriteDouble(MOCK_LATITUDE); // latitude
87     parcel.WriteInt32(1); // hasLongitude
88     parcel.WriteDouble(MOCK_LONGITUDE); // longitude
89     parcel.WriteString16(u"phoneNumber");
90     parcel.WriteString16(u"addressUrl");
91     parcel.WriteBool(true);
92     geoAddress->ReadFromParcel(parcel);
93 }
94 
VerifyGeoAddressReadFromParcel(std::unique_ptr<GeoAddress> & geoAddress)95 void LocationCommonTest::VerifyGeoAddressReadFromParcel(std::unique_ptr<GeoAddress>& geoAddress)
96 {
97     EXPECT_EQ("localeLanguage", geoAddress->m_localeLanguage);
98     EXPECT_EQ("localeCountry", geoAddress->m_localeCountry);
99     EXPECT_EQ(1, geoAddress->m_descriptions.size());
100     auto iter = geoAddress->m_descriptions.find(0);
101     EXPECT_EQ(true, iter != geoAddress->m_descriptions.end());
102     EXPECT_EQ(0, iter->first);
103     EXPECT_EQ("line", iter->second);
104     EXPECT_EQ("placeName", geoAddress->m_placeName);
105     EXPECT_EQ("administrativeArea", geoAddress->m_administrativeArea);
106     EXPECT_EQ("subAdministrativeArea", geoAddress->m_subAdministrativeArea);
107     EXPECT_EQ("locality", geoAddress->m_locality);
108     EXPECT_EQ("subLocality", geoAddress->m_subLocality);
109     EXPECT_EQ("roadName", geoAddress->m_roadName);
110     EXPECT_EQ("subRoadName", geoAddress->m_subRoadName);
111     EXPECT_EQ("premises", geoAddress->m_premises);
112     EXPECT_EQ("postalCode", geoAddress->m_postalCode);
113     EXPECT_EQ("countryCode", geoAddress->m_countryCode);
114     EXPECT_EQ("countryName", geoAddress->m_countryName);
115     EXPECT_EQ(1, geoAddress->m_hasLatitude);
116     EXPECT_EQ(MOCK_LATITUDE, geoAddress->m_latitude);
117     EXPECT_EQ(1, geoAddress->m_hasLongitude);
118     EXPECT_EQ(MOCK_LONGITUDE, geoAddress->m_longitude);
119     EXPECT_EQ("phoneNumber", geoAddress->m_phoneNumber);
120     EXPECT_EQ("addressUrl", geoAddress->m_addressUrl);
121     EXPECT_EQ(true, geoAddress->m_isFromMock);
122 }
123 
VerifyGeoAddressMarshalling(MessageParcel & newParcel)124 void LocationCommonTest::VerifyGeoAddressMarshalling(MessageParcel& newParcel)
125 {
126     EXPECT_EQ("localeLanguage", Str16ToStr8(newParcel.ReadString16()));
127     EXPECT_EQ("localeCountry", Str16ToStr8(newParcel.ReadString16()));
128     EXPECT_EQ(1, newParcel.ReadInt32());
129     EXPECT_EQ(0, newParcel.ReadInt32());
130     EXPECT_EQ("line", Str16ToStr8(newParcel.ReadString16()));
131     EXPECT_EQ("placeName", Str16ToStr8(newParcel.ReadString16()));
132     EXPECT_EQ("administrativeArea", Str16ToStr8(newParcel.ReadString16()));
133     EXPECT_EQ("subAdministrativeArea", Str16ToStr8(newParcel.ReadString16()));
134     EXPECT_EQ("locality", Str16ToStr8(newParcel.ReadString16()));
135     EXPECT_EQ("subLocality", Str16ToStr8(newParcel.ReadString16()));
136     EXPECT_EQ("roadName", Str16ToStr8(newParcel.ReadString16()));
137     EXPECT_EQ("subRoadName", Str16ToStr8(newParcel.ReadString16()));
138     EXPECT_EQ("premises", Str16ToStr8(newParcel.ReadString16()));
139     EXPECT_EQ("postalCode", Str16ToStr8(newParcel.ReadString16()));
140     EXPECT_EQ("countryCode", Str16ToStr8(newParcel.ReadString16()));
141     EXPECT_EQ("countryName", Str16ToStr8(newParcel.ReadString16()));
142     EXPECT_EQ(1, newParcel.ReadInt32());
143     EXPECT_EQ(MOCK_LATITUDE, newParcel.ReadDouble());
144     EXPECT_EQ(1, newParcel.ReadInt32());
145     EXPECT_EQ(MOCK_LONGITUDE, newParcel.ReadDouble());
146     EXPECT_EQ("phoneNumber", Str16ToStr8(newParcel.ReadString16()));
147     EXPECT_EQ("addressUrl", Str16ToStr8(newParcel.ReadString16()));
148     EXPECT_EQ(true, newParcel.ReadBool());
149 }
150 
VerifyLocationMarshalling(MessageParcel & newParcel)151 void LocationCommonTest::VerifyLocationMarshalling(MessageParcel& newParcel)
152 {
153     EXPECT_EQ(VERIFY_LOCATION_LATITUDE, newParcel.ReadDouble()); // latitude
154     EXPECT_EQ(VERIFY_LOCATION_LONGITUDE, newParcel.ReadDouble()); // longitude
155     EXPECT_EQ(VERIFY_LOCATION_ALTITUDE, newParcel.ReadDouble()); // altitude
156     EXPECT_EQ(VERIFY_LOCATION_ACCURACY, newParcel.ReadDouble()); // accuracy
157     EXPECT_EQ(VERIFY_LOCATION_SPEED, newParcel.ReadDouble()); // speed
158     EXPECT_EQ(VERIFY_LOCATION_DIRECTION, newParcel.ReadDouble()); // direction
159     EXPECT_EQ(VERIFY_LOCATION_TIME, newParcel.ReadInt64()); // timeStamp
160     EXPECT_EQ(VERIFY_LOCATION_TIMESINCEBOOT, newParcel.ReadInt64()); // timeSinceBoot
161     EXPECT_EQ("additions", Str16ToStr8(newParcel.ReadString16())); // additions
162     EXPECT_EQ(1, newParcel.ReadInt64()); // additionSize
163     EXPECT_EQ(true, newParcel.ReadBool()); // isFromMock
164     EXPECT_EQ(1, newParcel.ReadInt32()); // sourceType
165     EXPECT_EQ(0, newParcel.ReadInt32()); // floorNo
166     EXPECT_EQ(VERIFY_LOCATION_FLOOR_ACC, newParcel.ReadDouble()); // floorAccuracy
167 }
168 
169 /*
170  * @tc.name: GeoAddressTest001
171  * @tc.desc: read from parcel.
172  * @tc.type: FUNC
173  */
174 HWTEST_F(LocationCommonTest, GeoAddressTest001, TestSize.Level1)
175 {
176     GTEST_LOG_(INFO)
177         << "LocationCommonTest, GeoAddressTest001, TestSize.Level1";
178     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressTest001 begin");
179     std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
180     SetGeoAddress(geoAddress);
181     VerifyGeoAddressReadFromParcel(geoAddress);
182 
183     MessageParcel newParcel;
184     geoAddress->Marshalling(newParcel);
185     VerifyGeoAddressMarshalling(newParcel);
186     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressTest001 end");
187 }
188 
189 /*
190  * @tc.name: GeoAddressTest001
191  * @tc.desc: read from parcel.
192  * @tc.type: FUNC
193  */
194 HWTEST_F(LocationCommonTest, GeoAddressTest002, TestSize.Level1)
195 {
196     std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
197     geoAddress->m_hasLatitude = true;
198     geoAddress->m_latitude = 1.0;
199     EXPECT_EQ(1.0, geoAddress->GetLatitude());
200 
201     geoAddress->m_hasLatitude = false;
202     EXPECT_EQ(0.0, geoAddress->GetLatitude());
203 
204     geoAddress->m_hasLongitude = true;
205     geoAddress->m_longitude = 1.0;
206     EXPECT_EQ(1.0, geoAddress->GetLongitude());
207 
208     geoAddress->m_hasLongitude = false;
209     EXPECT_EQ(0.0, geoAddress->GetLongitude());
210 }
211 
212 /*
213  * @tc.name: LocationTest001
214  * @tc.desc: read from parcel.
215  * @tc.type: FUNC
216  */
217 HWTEST_F(LocationCommonTest, LocationTest001, TestSize.Level1)
218 {
219     GTEST_LOG_(INFO)
220         << "LocationCommonTest, LocationTest001, TestSize.Level1";
221     LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest001 begin");
222     auto location = std::make_shared<Location>();
223     MessageParcel parcel;
224     parcel.WriteDouble(VERIFY_LOCATION_LATITUDE); // latitude
225     parcel.WriteDouble(VERIFY_LOCATION_LONGITUDE); // longitude
226     parcel.WriteDouble(VERIFY_LOCATION_ALTITUDE); // altitude
227     parcel.WriteDouble(VERIFY_LOCATION_ACCURACY); // accuracy
228     parcel.WriteDouble(VERIFY_LOCATION_SPEED); // speed
229     parcel.WriteDouble(VERIFY_LOCATION_DIRECTION); // direction
230     parcel.WriteInt64(VERIFY_LOCATION_TIME); // timeStamp
231     parcel.WriteInt64(VERIFY_LOCATION_TIMESINCEBOOT); // timeSinceBoot
232     parcel.WriteString16(u"additions"); // additions
233     parcel.WriteInt64(1); // additionSize
234     parcel.WriteBool(true); // isFromMock
235     parcel.WriteInt32(1); // source type
236     parcel.WriteInt32(0); // floor no.
237     parcel.WriteDouble(VERIFY_LOCATION_FLOOR_ACC); // floor acc
238     location->ReadFromParcel(parcel);
239     EXPECT_EQ(VERIFY_LOCATION_LATITUDE, location->GetLatitude());
240     EXPECT_EQ(VERIFY_LOCATION_LONGITUDE, location->GetLongitude());
241     EXPECT_EQ(VERIFY_LOCATION_ALTITUDE, location->GetAltitude());
242     EXPECT_EQ(VERIFY_LOCATION_ACCURACY, location->GetAccuracy());
243     EXPECT_EQ(VERIFY_LOCATION_SPEED, location->GetSpeed());
244     EXPECT_EQ(VERIFY_LOCATION_DIRECTION, location->GetDirection());
245     EXPECT_EQ(VERIFY_LOCATION_TIME, location->GetTimeStamp());
246     EXPECT_EQ(VERIFY_LOCATION_TIMESINCEBOOT, location->GetTimeSinceBoot());
247     EXPECT_EQ("additions", location->GetAdditions());
248     EXPECT_EQ(1, location->GetAdditionSize());
249     EXPECT_EQ(true, location->GetIsFromMock());
250     EXPECT_EQ(1, location->GetSourceType());
251     EXPECT_EQ(0, location->GetFloorNo());
252     EXPECT_EQ(VERIFY_LOCATION_FLOOR_ACC, location->GetFloorAccuracy());
253 
254     MessageParcel newParcel;
255     location->Marshalling(newParcel);
256     VerifyLocationMarshalling(newParcel);
257     LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest001 end");
258 }
259 
260 /*
261  * @tc.name: SateLLiteStatusTest001
262  * @tc.desc: read from parcel.
263  * @tc.type: FUNC
264  */
265 HWTEST_F(LocationCommonTest, SateLLiteStatusTest001, TestSize.Level1)
266 {
267     GTEST_LOG_(INFO)
268         << "LocationCommonTest, SateLLiteStatusTest001, TestSize.Level1";
269     LBSLOGI(LOCATOR, "[LocationCommonTest] SateLLiteStatusTest001 begin");
270     SatelliteStatus oldStatus;
271     std::unique_ptr<SatelliteStatus> status = std::make_unique<SatelliteStatus>(oldStatus);
272     MessageParcel parcel;
273     int sateNum = 2;
274     parcel.WriteInt64(2); // satellitesNumber
275     for (int i = 0; i < sateNum; i++) {
276         parcel.WriteInt64(i); // satelliteId
277         parcel.WriteDouble(i + 1.0); // carrierToNoiseDensity
278         parcel.WriteDouble(i + 2.0); // altitude
279         parcel.WriteDouble(i + 3.0); // azimuth
280         parcel.WriteDouble(i + 4.0); // carrierFrequency
281     }
282     status->ReadFromParcel(parcel);
283     EXPECT_EQ(2, status->GetSatellitesNumber());
284     for (int i = 0; i < sateNum; i++) {
285         EXPECT_EQ(i, status->GetSatelliteIds()[i]);
286         EXPECT_EQ(i + 1.0, status->GetCarrierToNoiseDensitys()[i]);
287         EXPECT_EQ(i + 2.0, status->GetAltitudes()[i]);
288         EXPECT_EQ(i + 3.0, status->GetAzimuths()[i]);
289         EXPECT_EQ(i + 4.0, status->GetCarrierFrequencies()[i]);
290     }
291 
292     MessageParcel newParcel;
293     status->Marshalling(newParcel);
294     EXPECT_EQ(2, newParcel.ReadInt64());
295     for (int i = 0; i < sateNum; i++) {
296         EXPECT_EQ(i, newParcel.ReadInt64());
297         EXPECT_EQ(i + 1.0, newParcel.ReadDouble());
298         EXPECT_EQ(i + 2.0, newParcel.ReadDouble());
299         EXPECT_EQ(i + 3.0, newParcel.ReadDouble());
300         EXPECT_EQ(i + 4.0, newParcel.ReadDouble());
301     }
302     LBSLOGI(LOCATOR, "[LocationCommonTest] SateLLiteStatusTest001 end");
303 }
304 
305 /*
306  * @tc.name: RequestConfigTest001
307  * @tc.desc: read from parcel.
308  * @tc.type: FUNC
309  */
310 HWTEST_F(LocationCommonTest, RequestConfigTest001, TestSize.Level1)
311 {
312     GTEST_LOG_(INFO)
313         << "LocationCommonTest, RequestConfigTest001, TestSize.Level1";
314     LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest001 begin");
315     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
316     MessageParcel parcel;
317     parcel.WriteInt32(1); // scenario
318     parcel.WriteInt32(2); // priority
319     parcel.WriteInt32(3); // timeInterval
320     parcel.WriteInt32(10); // distanceInterval
321     parcel.WriteFloat(1000.0); // maxAccuracy
322     parcel.WriteInt32(1); // fixNumber
323     requestConfig->ReadFromParcel(parcel);
324     EXPECT_EQ(1, requestConfig->GetScenario());
325     EXPECT_EQ(2, requestConfig->GetPriority());
326     EXPECT_EQ(3, requestConfig->GetTimeInterval());
327     EXPECT_EQ(10, requestConfig->GetDistanceInterval());
328     EXPECT_EQ(1000.0, requestConfig->GetMaxAccuracy());
329     EXPECT_EQ(1, requestConfig->GetFixNumber());
330 
331     MessageParcel newParcel;
332     requestConfig->Marshalling(newParcel);
333     EXPECT_EQ(1, newParcel.ReadInt32());
334     EXPECT_EQ(2, newParcel.ReadInt32());
335     EXPECT_EQ(3, newParcel.ReadInt32());
336     EXPECT_EQ(10, newParcel.ReadInt32());
337     EXPECT_EQ(1000.0, newParcel.ReadFloat());
338     EXPECT_EQ(1, newParcel.ReadInt32());
339     LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest001 end");
340 }
341 
342 HWTEST_F(LocationCommonTest, RequestConfigTest002, TestSize.Level1)
343 {
344     GTEST_LOG_(INFO)
345         << "LocationCommonTest, RequestConfigTest002, TestSize.Level1";
346     LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest002 begin");
347     std::unique_ptr<RequestConfig> requestConfigForCompare =
348         std::make_unique<RequestConfig>();
349 
350     RequestConfig requestConfigForSet1;
351     requestConfigForSet1.SetScenario(1);
352     requestConfigForSet1.SetPriority(2);
353     requestConfigForSet1.SetTimeInterval(3);
354     requestConfigForSet1.SetDistanceInterval(4);
355     requestConfigForSet1.SetMaxAccuracy(1000.0); // accuracy
356     requestConfigForSet1.SetFixNumber(1);
357     requestConfigForCompare->Set(requestConfigForSet1);
358     EXPECT_NE("", requestConfigForCompare->ToString());
359     EXPECT_EQ(true, requestConfigForCompare->IsSame(requestConfigForSet1));
360 
361     RequestConfig requestConfigForSet2;
362     requestConfigForSet2.SetScenario(2);
363     EXPECT_NE("", requestConfigForCompare->ToString());
364     EXPECT_EQ(false, requestConfigForCompare->IsSame(requestConfigForSet2));
365 
366     RequestConfig requestConfigForSet3;
367     requestConfigForSet3.SetScenario(SCENE_UNSET);
368     requestConfigForSet3.SetPriority(2);
369     requestConfigForCompare->SetScenario(SCENE_UNSET);
370     EXPECT_NE("", requestConfigForCompare->ToString());
371     EXPECT_EQ(true, requestConfigForCompare->IsSame(requestConfigForSet3));
372 
373     RequestConfig requestConfigForSet4;
374     requestConfigForSet4.SetScenario(SCENE_UNSET);
375     requestConfigForSet4.SetPriority(1);
376     requestConfigForCompare->SetScenario(SCENE_UNSET);
377     EXPECT_NE("", requestConfigForCompare->ToString());
378     EXPECT_EQ(false, requestConfigForCompare->IsSame(requestConfigForSet4));
379     LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest002 end");
380 }
381 
382 /*
383  * @tc.name: GeocodingMockInfoTest001
384  * @tc.desc: read from parcel.
385  * @tc.type: FUNC
386  */
387 HWTEST_F(LocationCommonTest, GeocodingMockInfoTest001, TestSize.Level1)
388 {
389     GTEST_LOG_(INFO)
390         << "LocationCommonTest, GeocodingMockInfoTest001, TestSize.Level1";
391     LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest001 begin");
392     MessageParcel parcel;
393     parcel.WriteString16(Str8ToStr16("locale"));
394     parcel.WriteDouble(12.0); // latitude
395     parcel.WriteDouble(13.0); // longitude
396     parcel.WriteInt32(1); // maxItems
397     std::unique_ptr<GeocodingMockInfo> mockInfo = std::make_unique<GeocodingMockInfo>();
398     mockInfo->ReadFromParcel(parcel);
399     std::shared_ptr<ReverseGeocodeRequest> reverseGeocodeRequest = mockInfo->GetLocation();
400     EXPECT_EQ(true, reverseGeocodeRequest != nullptr);
401     EXPECT_EQ("locale", reverseGeocodeRequest->locale);
402     EXPECT_EQ(12.0, reverseGeocodeRequest->latitude);
403     EXPECT_EQ(13.0, reverseGeocodeRequest->longitude);
404     EXPECT_EQ(1, reverseGeocodeRequest->maxItems);
405 
406     MessageParcel newParcel;
407     mockInfo->Marshalling(newParcel);
408     EXPECT_EQ("locale", Str16ToStr8(newParcel.ReadString16()));
409     EXPECT_EQ(12.0, newParcel.ReadDouble());
410     EXPECT_EQ(13.0, newParcel.ReadDouble());
411     EXPECT_EQ(1, newParcel.ReadInt32());
412     LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest001 end");
413 }
414 
415 HWTEST_F(LocationCommonTest, AppIdentityTest001, TestSize.Level1)
416 {
417     GTEST_LOG_(INFO)
418         << "LocationCommonTest, AppIdentityTest001, TestSize.Level1";
419     LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest001 begin");
420     AppIdentity identity;
421     identity.SetPid(1);
422     identity.SetUid(2);
423     identity.SetTokenId(3);
424     identity.SetFirstTokenId(4);
425     identity.SetBundleName("bundleName");
426     EXPECT_EQ(1, identity.GetPid());
427     EXPECT_EQ(2, identity.GetUid());
428     EXPECT_EQ(3, identity.GetTokenId());
429     EXPECT_EQ(4, identity.GetFirstTokenId());
430     EXPECT_EQ("bundleName", identity.GetBundleName());
431     EXPECT_NE("", identity.ToString());
432     LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest001 end");
433 }
434 
435 HWTEST_F(LocationCommonTest, CommonHisyseventTest001, TestSize.Level1)
436 {
437     GTEST_LOG_(INFO)
438         << "LocationCommonTest, CommonHisyseventTest001, TestSize.Level1";
439     LBSLOGI(LOCATOR, "[LocationCommonTest] CommonHisyseventTest001 begin");
440     std::string state = "state";
441     pid_t pid = 1;
442     pid_t uid = 2;
443     WriteGnssStateEvent(state, pid, uid);
444     WriteLocationSwitchStateEvent(state);
445     LBSLOGI(LOCATOR, "[LocationCommonTest] CommonHisyseventTest001 end");
446 }
447 
448 HWTEST_F(LocationCommonTest, GeoFenceStateTest001, TestSize.Level1)
449 {
450     GTEST_LOG_(INFO)
451         << "LocationCommonTest, GeoFenceStateTest001, TestSize.Level1";
452     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoFenceStateTest001 begin");
453     GeoFence fence;
454     fence.latitude = 1.0;
455     fence.longitude = 2.0;
456     fence.radius = 3.0;
457     fence.expiration = 4.0;
458     auto wantAgent = AbilityRuntime::WantAgent::WantAgent();
459     auto state = new (std::nothrow) GeoFenceState(fence, wantAgent);
460     EXPECT_NE(nullptr, state);
461     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoFenceStateTest001 end");
462 }
463 
464 HWTEST_F(LocationCommonTest, GeocodingMockInfoTest002, TestSize.Level1)
465 {
466     GTEST_LOG_(INFO)
467         << "LocationCommonTest, GeocodingMockInfoTest002, TestSize.Level1";
468     LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest002 begin");
469     std::unique_ptr<GeocodingMockInfo> mockInfo = std::make_unique<GeocodingMockInfo>();
470 
471     auto reverseGeocodeRequest = std::make_shared<ReverseGeocodeRequest>();
472     mockInfo->SetLocation(reverseGeocodeRequest);
473     EXPECT_NE(nullptr, mockInfo->GetLocation());
474 
475     std::shared_ptr<GeoAddress> geoAddress = std::make_shared<GeoAddress>();
476     mockInfo->SetGeoAddressInfo(geoAddress);
477     EXPECT_NE(nullptr, mockInfo->GetGeoAddressInfo());
478     LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest002 end");
479 }
480 
481 HWTEST_F(LocationCommonTest, PermStateChangeCallbackTest001, TestSize.Level1)
482 {
483     GTEST_LOG_(INFO)
484         << "LocationCommonTest, PermStateChangeCallbackTest001, TestSize.Level1";
485     LBSLOGI(LOCATOR, "[LocationCommonTest] PermStateChangeCallbackTest001 begin");
486     uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
487     PermStateChangeScope scopeInfo;
488     scopeInfo.permList = {"ohos.permission.LOCATION"};
489     scopeInfo.tokenIDs = {callingTokenId};
490     auto callbackPtr = std::make_shared<PermissionStatusChangeCb>(scopeInfo);
491     struct PermStateChangeInfo result{0, callingTokenId, ACCESS_LOCATION};
492     callbackPtr->PermStateChangeCallback(result);
493     LBSLOGI(LOCATOR, "[LocationCommonTest] PermStateChangeCallbackTest001 end");
494 }
495 
496 HWTEST_F(LocationCommonTest, LocatorEventSubscriberTest001, TestSize.Level1)
497 {
498     GTEST_LOG_(INFO)
499         << "LocationCommonTest, LocatorEventSubscriberTest001, TestSize.Level1";
500     LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest001 begin");
501     OHOS::EventFwk::MatchingSkills matchingSkills;
502     matchingSkills.AddEvent(MODE_CHANGED_EVENT);
503     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
504     auto locatorEventSubscriber = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
505     Want want;
506     want.SetAction("usual.event.location.MODE_STATE_CHANGED");
507     OHOS::EventFwk::CommonEventData data;
508     data.SetWant(want);
509     locatorEventSubscriber->OnReceiveEvent(data);
510     LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest001 end");
511 }
512 
513 HWTEST_F(LocationCommonTest, LocatorEventSubscriberTest002, TestSize.Level1)
514 {
515     GTEST_LOG_(INFO)
516         << "LocationCommonTest, LocatorEventSubscriberTest002, TestSize.Level1";
517     LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest002 begin");
518     OHOS::EventFwk::MatchingSkills matchingSkills;
519     matchingSkills.AddEvent(MODE_CHANGED_EVENT);
520     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
521     auto locatorEventSubscriber = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
522     Want want;
523     want.SetAction("Invalid action");
524     OHOS::EventFwk::CommonEventData data;
525     data.SetWant(want);
526     locatorEventSubscriber->OnReceiveEvent(data);
527     LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest002 end");
528 }
529 
530 HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest001, TestSize.Level1)
531 {
532     GTEST_LOG_(INFO)
533         << "LocationCommonTest, GeoAddressDescriptionsTest001, TestSize.Level1";
534     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest001 begin");
535     std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
536     SetGeoAddress(geoAddress);
537     geoAddress->GetDescriptions(0);
538     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest001 end");
539 }
540 
541 HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest002, TestSize.Level1)
542 {
543     GTEST_LOG_(INFO)
544         << "LocationCommonTest, GeoAddressDescriptionsTest002, TestSize.Level1";
545     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest002 begin");
546     std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
547     SetGeoAddress(geoAddress);
548     geoAddress->GetDescriptions(1);
549     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest002 end");
550 }
551 
552 HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest003, TestSize.Level1)
553 {
554     GTEST_LOG_(INFO)
555         << "LocationCommonTest, GeoAddressDescriptionsTest003, TestSize.Level1";
556     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest003 begin");
557     std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
558     SetGeoAddress(geoAddress);
559     geoAddress->GetDescriptions(-1);
560     LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest003 end");
561 }
562 } // namespace Location
563 } // namespace OHOS