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 #define private public
21 #include "request.h"
22 #include "location.h"
23 #include "request_config.h"
24 #undef private
25
26 #include "message_parcel.h"
27 #include "ipc_skeleton.h"
28 #include "common_event_subscriber.h"
29 #include "common_event_manager.h"
30 #include "common_event_support.h"
31 #include "system_ability_definition.h"
32 #include "want.h"
33 #include "want_agent.h"
34
35 #include "app_identity.h"
36 #include "common_hisysevent.h"
37 #include "common_utils.h"
38 #include "country_code_manager.h"
39 #include "constant_definition.h"
40 #include "permission_status_change_cb.h"
41 #ifdef FEATURE_GEOCODE_SUPPORT
42 #include "geo_address.h"
43 #include "geocoding_mock_info.h"
44 #endif
45 #include "location_data_rdb_helper.h"
46 #include "location_data_rdb_manager.h"
47 #include "location_log.h"
48 #define private public
49 #include "location_data_rdb_observer.h"
50 #include "location_sa_load_manager.h"
51 #undef private
52 #include "locator_event_subscriber.h"
53 #include "request_config.h"
54 #ifdef FEATURE_GNSS_SUPPORT
55 #include "satellite_status.h"
56 #endif
57 #include "hook_utils.h"
58 #include "hookmgr.h"
59 #include "permission_manager.h"
60 #include "lbs_res_loader.h"
61
62 using namespace testing::ext;
63 namespace OHOS {
64 namespace Location {
65 using Want = OHOS::AAFwk::Want;
66 #ifdef FEATURE_GEOCODE_SUPPORT
67 const double MOCK_LATITUDE = 99.0;
68 const double MOCK_LONGITUDE = 100.0;
69 #endif
70 const double VERIFY_LOCATION_LATITUDE = 12.0;
71 const double VERIFY_LOCATION_LONGITUDE = 13.0;
72 const double VERIFY_LOCATION_ALTITUDE = 14.0;
73 const double VERIFY_LOCATION_ACCURACY = 1000.0;
74 const double VERIFY_LOCATION_SPEED = 10.0;
75 const double VERIFY_LOCATION_DIRECTION = 90.0;
76 const double VERIFY_LOCATION_TIME = 1000000000;
77 const double VERIFY_LOCATION_TIMESINCEBOOT = 1000000000;
78 const int32_t UN_SAID = 999999;
79 const std::string UN_URI = "unknown_uri";
SetUp()80 void LocationCommonTest::SetUp()
81 {
82 }
83
TearDown()84 void LocationCommonTest::TearDown()
85 {
86 }
87
88 #ifdef FEATURE_GEOCODE_SUPPORT
SetGeoAddress(std::unique_ptr<GeoAddress> & geoAddress)89 void LocationCommonTest::SetGeoAddress(std::unique_ptr<GeoAddress>& geoAddress)
90 {
91 MessageParcel parcel;
92 parcel.WriteDouble(MOCK_LATITUDE); // latitude
93 parcel.WriteDouble(MOCK_LONGITUDE); // longitude
94 parcel.WriteString16(u"locale");
95 parcel.WriteString16(u"placeName");
96 parcel.WriteString16(u"countryCode");
97 parcel.WriteString16(u"countryName");
98 parcel.WriteString16(u"administrativeArea");
99 parcel.WriteString16(u"subAdministrativeArea");
100 parcel.WriteString16(u"locality");
101 parcel.WriteString16(u"subLocality");
102 parcel.WriteString16(u"roadName");
103 parcel.WriteString16(u"subRoadName");
104 parcel.WriteString16(u"premises");
105 parcel.WriteString16(u"postalCode");
106 parcel.WriteString16(u"phoneNumber");
107 parcel.WriteString16(u"addressUrl");
108 parcel.WriteInt32(1);
109 parcel.WriteInt32(0);
110 parcel.WriteString16(u"line");
111 parcel.WriteBool(true);
112 geoAddress->ReadFromParcel(parcel);
113 }
114 #endif
115
116 #ifdef FEATURE_GEOCODE_SUPPORT
VerifyGeoAddressReadFromParcel(std::unique_ptr<GeoAddress> & geoAddress)117 void LocationCommonTest::VerifyGeoAddressReadFromParcel(std::unique_ptr<GeoAddress>& geoAddress)
118 {
119 EXPECT_EQ(MOCK_LATITUDE, geoAddress->latitude_);
120 EXPECT_EQ(MOCK_LONGITUDE, geoAddress->longitude_);
121 EXPECT_EQ("locale", geoAddress->locale_);
122 EXPECT_EQ("placeName", geoAddress->placeName_);
123 EXPECT_EQ("countryCode", geoAddress->countryCode_);
124 EXPECT_EQ("countryName", geoAddress->countryName_);
125 EXPECT_EQ("administrativeArea", geoAddress->administrativeArea_);
126 EXPECT_EQ("subAdministrativeArea", geoAddress->subAdministrativeArea_);
127 EXPECT_EQ("locality", geoAddress->locality_);
128 EXPECT_EQ("subLocality", geoAddress->subLocality_);
129 EXPECT_EQ("roadName", geoAddress->roadName_);
130 EXPECT_EQ("subRoadName", geoAddress->subRoadName_);
131 EXPECT_EQ("premises", geoAddress->premises_);
132 EXPECT_EQ("postalCode", geoAddress->postalCode_);
133 EXPECT_EQ("phoneNumber", geoAddress->phoneNumber_);
134 EXPECT_EQ("addressUrl", geoAddress->addressUrl_);
135 EXPECT_EQ(1, geoAddress->descriptions_.size());
136 auto iter = geoAddress->descriptions_.find(0);
137 EXPECT_EQ(true, iter != geoAddress->descriptions_.end());
138 EXPECT_EQ(0, iter->first);
139 EXPECT_EQ("line", iter->second);
140 EXPECT_EQ(true, geoAddress->isFromMock_);
141 }
142 #endif
143
144 #ifdef FEATURE_GEOCODE_SUPPORT
VerifyGeoAddressMarshalling(MessageParcel & newParcel)145 void LocationCommonTest::VerifyGeoAddressMarshalling(MessageParcel& newParcel)
146 {
147 EXPECT_EQ(MOCK_LATITUDE, newParcel.ReadDouble());
148 EXPECT_EQ(MOCK_LONGITUDE, newParcel.ReadDouble());
149 EXPECT_EQ("locale", Str16ToStr8(newParcel.ReadString16()));
150 EXPECT_EQ("placeName", Str16ToStr8(newParcel.ReadString16()));
151 EXPECT_EQ("countryCode", Str16ToStr8(newParcel.ReadString16()));
152 EXPECT_EQ("countryName", Str16ToStr8(newParcel.ReadString16()));
153 EXPECT_EQ("administrativeArea", Str16ToStr8(newParcel.ReadString16()));
154 EXPECT_EQ("subAdministrativeArea", Str16ToStr8(newParcel.ReadString16()));
155 EXPECT_EQ("locality", Str16ToStr8(newParcel.ReadString16()));
156 EXPECT_EQ("subLocality", Str16ToStr8(newParcel.ReadString16()));
157 EXPECT_EQ("roadName", Str16ToStr8(newParcel.ReadString16()));
158 EXPECT_EQ("subRoadName", Str16ToStr8(newParcel.ReadString16()));
159 EXPECT_EQ("premises", Str16ToStr8(newParcel.ReadString16()));
160 EXPECT_EQ("postalCode", Str16ToStr8(newParcel.ReadString16()));
161 EXPECT_EQ("phoneNumber", Str16ToStr8(newParcel.ReadString16()));
162 EXPECT_EQ("addressUrl", Str16ToStr8(newParcel.ReadString16()));
163 EXPECT_EQ(1, newParcel.ReadInt32());
164 EXPECT_EQ(0, newParcel.ReadInt32());
165 EXPECT_EQ("line", Str16ToStr8(newParcel.ReadString16()));
166 EXPECT_EQ(true, newParcel.ReadBool());
167 }
168 #endif
169
VerifyLocationMarshalling(MessageParcel & newParcel)170 void LocationCommonTest::VerifyLocationMarshalling(MessageParcel& newParcel)
171 {
172 EXPECT_EQ(VERIFY_LOCATION_LATITUDE, newParcel.ReadDouble()); // latitude
173 EXPECT_EQ(VERIFY_LOCATION_LONGITUDE, newParcel.ReadDouble()); // longitude
174 EXPECT_EQ(VERIFY_LOCATION_ALTITUDE, newParcel.ReadDouble()); // altitude
175 EXPECT_EQ(VERIFY_LOCATION_ACCURACY, newParcel.ReadDouble()); // accuracy
176 EXPECT_EQ(VERIFY_LOCATION_SPEED, newParcel.ReadDouble()); // speed
177 EXPECT_EQ(VERIFY_LOCATION_DIRECTION, newParcel.ReadDouble()); // direction
178 EXPECT_EQ(VERIFY_LOCATION_TIME, newParcel.ReadInt64()); // timeStamp
179 EXPECT_EQ(VERIFY_LOCATION_TIMESINCEBOOT, newParcel.ReadInt64()); // timeSinceBoot
180 EXPECT_EQ(1, newParcel.ReadInt64()); // additionSize
181 std::vector<std::u16string> additions;
182 newParcel.ReadString16Vector(&additions);
183 EXPECT_EQ("additions", Str16ToStr8(additions[0])); // additions
184 EXPECT_EQ(1, newParcel.ReadInt32()); // isFromMock
185 }
186
187 /*
188 * @tc.name: GeoAddressTest001
189 * @tc.desc: read from parcel.
190 * @tc.type: FUNC
191 */
192 #ifdef FEATURE_GEOCODE_SUPPORT
193 HWTEST_F(LocationCommonTest, GeoAddressTest001, TestSize.Level1)
194 {
195 GTEST_LOG_(INFO)
196 << "LocationCommonTest, GeoAddressTest001, TestSize.Level1";
197 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressTest001 begin");
198 std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
199 SetGeoAddress(geoAddress);
200 VerifyGeoAddressReadFromParcel(geoAddress);
201
202 MessageParcel newParcel;
203 geoAddress->Marshalling(newParcel);
204 VerifyGeoAddressMarshalling(newParcel);
205 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressTest001 end");
206 }
207 #endif
208
209 /*
210 * @tc.name: GeoAddressTest001
211 * @tc.desc: read from parcel.
212 * @tc.type: FUNC
213 */
214 #ifdef FEATURE_GEOCODE_SUPPORT
215 HWTEST_F(LocationCommonTest, GeoAddressTest002, TestSize.Level1)
216 {
217 std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
218
219 geoAddress->latitude_ = 1.0;
220 EXPECT_EQ(1.0, geoAddress->GetLatitude());
221
222 geoAddress->longitude_ = 1.0;
223 EXPECT_EQ(1.0, geoAddress->GetLongitude());
224 }
225 #endif
226
227 /*
228 * @tc.name: LocationTest001
229 * @tc.desc: read from parcel.
230 * @tc.type: FUNC
231 */
232 HWTEST_F(LocationCommonTest, LocationTest001, TestSize.Level0)
233 {
234 GTEST_LOG_(INFO)
235 << "LocationCommonTest, LocationTest001, TestSize.Level1";
236 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest001 begin");
237 auto location = std::make_shared<Location>();
238 MessageParcel parcel;
239 parcel.WriteDouble(VERIFY_LOCATION_LATITUDE); // latitude
240 parcel.WriteDouble(VERIFY_LOCATION_LONGITUDE); // longitude
241 parcel.WriteDouble(VERIFY_LOCATION_ALTITUDE); // altitude
242 parcel.WriteDouble(VERIFY_LOCATION_ACCURACY); // accuracy
243 parcel.WriteDouble(VERIFY_LOCATION_SPEED); // speed
244 parcel.WriteDouble(VERIFY_LOCATION_DIRECTION); // direction
245 parcel.WriteInt64(VERIFY_LOCATION_TIME); // timeStamp
246 parcel.WriteInt64(VERIFY_LOCATION_TIMESINCEBOOT); // timeSinceBoot
247 parcel.WriteInt64(1); // additionSize
248 std::vector<std::u16string> additions;
249 additions.push_back(Str8ToStr16("additions"));
250 parcel.WriteString16Vector(additions);
251 parcel.WriteInt32(1); // isFromMock
252 location->ReadFromParcel(parcel);
253 EXPECT_EQ(VERIFY_LOCATION_LATITUDE, location->GetLatitude());
254 EXPECT_EQ(VERIFY_LOCATION_LONGITUDE, location->GetLongitude());
255 EXPECT_EQ(VERIFY_LOCATION_ALTITUDE, location->GetAltitude());
256 EXPECT_EQ(VERIFY_LOCATION_ACCURACY, location->GetAccuracy());
257 EXPECT_EQ(VERIFY_LOCATION_SPEED, location->GetSpeed());
258 EXPECT_EQ(VERIFY_LOCATION_DIRECTION, location->GetDirection());
259 EXPECT_EQ(VERIFY_LOCATION_TIME, location->GetTimeStamp());
260 EXPECT_EQ(VERIFY_LOCATION_TIMESINCEBOOT, location->GetTimeSinceBoot());
261 EXPECT_EQ(1, location->GetAdditionSize());
262 if (location->GetAdditions().size() == 1) {
263 EXPECT_EQ("additions", location->GetAdditions()[0]);
264 }
265 EXPECT_EQ(1, location->GetIsFromMock());
266
267 MessageParcel newParcel;
268 location->Marshalling(newParcel);
269 VerifyLocationMarshalling(newParcel);
270 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest001 end");
271 }
272
273 /*
274 * @tc.name: SateLLiteStatusTest001
275 * @tc.desc: read from parcel.
276 * @tc.type: FUNC
277 */
278 #ifdef FEATURE_GNSS_SUPPORT
279 HWTEST_F(LocationCommonTest, SateLLiteStatusTest001, TestSize.Level1)
280 {
281 GTEST_LOG_(INFO)
282 << "LocationCommonTest, SateLLiteStatusTest001, TestSize.Level1";
283 LBSLOGI(LOCATOR, "[LocationCommonTest] SateLLiteStatusTest001 begin");
284 SatelliteStatus oldStatus;
285 std::unique_ptr<SatelliteStatus> status = std::make_unique<SatelliteStatus>(oldStatus);
286 MessageParcel parcel;
287 int sateNum = 2;
288 parcel.WriteInt64(2); // satellitesNumber
289 for (int i = 0; i < sateNum; i++) {
290 parcel.WriteInt64(i); // satelliteId
291 parcel.WriteDouble(i + 1.0); // carrierToNoiseDensity
292 parcel.WriteDouble(i + 2.0); // altitude
293 parcel.WriteDouble(i + 3.0); // azimuth
294 parcel.WriteDouble(i + 4.0); // carrierFrequency
295 parcel.WriteInt64(i + 5.0); // constellation type
296 parcel.WriteInt64(i + 6.0); // additionalInfoList
297 }
298 status->ReadFromParcel(parcel);
299 EXPECT_EQ(2, status->GetSatellitesNumber());
300 for (int i = 0; i < sateNum; i++) {
301 EXPECT_EQ(i, status->GetSatelliteIds()[i]);
302 EXPECT_EQ(i + 1.0, status->GetCarrierToNoiseDensitys()[i]);
303 EXPECT_EQ(i + 2.0, status->GetAltitudes()[i]);
304 EXPECT_EQ(i + 3.0, status->GetAzimuths()[i]);
305 EXPECT_EQ(i + 4.0, status->GetCarrierFrequencies()[i]);
306 EXPECT_EQ(i + 5.0, status->GetConstellationTypes()[i]);
307 EXPECT_EQ(i + 6.0, status->GetSatelliteAdditionalInfoList()[i]);
308 }
309
310 MessageParcel newParcel;
311 status->Marshalling(newParcel);
312 EXPECT_EQ(2, newParcel.ReadInt64());
313 for (int i = 0; i < sateNum; i++) {
314 EXPECT_EQ(i, newParcel.ReadInt64());
315 EXPECT_EQ(i + 1.0, newParcel.ReadDouble());
316 EXPECT_EQ(i + 2.0, newParcel.ReadDouble());
317 EXPECT_EQ(i + 3.0, newParcel.ReadDouble());
318 EXPECT_EQ(i + 4.0, newParcel.ReadDouble());
319 EXPECT_EQ(i + 5.0, newParcel.ReadInt64());
320 EXPECT_EQ(i + 6.0, newParcel.ReadInt64());
321 }
322 LBSLOGI(LOCATOR, "[LocationCommonTest] SateLLiteStatusTest001 end");
323 }
324 #endif
325
326 /*
327 * @tc.name: RequestConfigTest001
328 * @tc.desc: read from parcel.
329 * @tc.type: FUNC
330 */
331 HWTEST_F(LocationCommonTest, RequestConfigTest001, TestSize.Level0)
332 {
333 GTEST_LOG_(INFO)
334 << "LocationCommonTest, RequestConfigTest001, TestSize.Level1";
335 LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest001 begin");
336 std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
337 MessageParcel parcel;
338 parcel.WriteInt32(1); // scenario
339 parcel.WriteInt32(2); // priority
340 parcel.WriteInt32(3); // timeInterval
341 parcel.WriteDouble(10.0); // distanceInterval
342 parcel.WriteFloat(1000.0); // maxAccuracy
343 parcel.WriteInt32(1); // fixNumber
344 requestConfig->ReadFromParcel(parcel);
345 EXPECT_EQ(1, requestConfig->GetScenario());
346 EXPECT_EQ(2, requestConfig->GetPriority());
347 EXPECT_EQ(3, requestConfig->GetTimeInterval());
348 EXPECT_EQ(10.0, requestConfig->GetDistanceInterval());
349 EXPECT_EQ(1000.0, requestConfig->GetMaxAccuracy());
350 EXPECT_EQ(1, requestConfig->GetFixNumber());
351
352 MessageParcel newParcel;
353 requestConfig->Marshalling(newParcel);
354 EXPECT_EQ(1, newParcel.ReadInt32());
355 EXPECT_EQ(2, newParcel.ReadInt32());
356 EXPECT_EQ(3, newParcel.ReadInt32());
357 EXPECT_EQ(10.0, newParcel.ReadDouble()); // distanceInterval
358 EXPECT_EQ(1000.0, newParcel.ReadFloat());
359 EXPECT_EQ(1, newParcel.ReadInt32());
360 LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest001 end");
361 }
362
363 HWTEST_F(LocationCommonTest, RequestConfigTest002, TestSize.Level1)
364 {
365 GTEST_LOG_(INFO)
366 << "LocationCommonTest, RequestConfigTest002, TestSize.Level1";
367 LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest002 begin");
368 std::unique_ptr<RequestConfig> requestConfigForCompare =
369 std::make_unique<RequestConfig>();
370
371 RequestConfig requestConfigForSet1;
372 requestConfigForSet1.SetScenario(1);
373 requestConfigForSet1.SetPriority(2);
374 requestConfigForSet1.SetTimeInterval(3);
375 requestConfigForSet1.SetDistanceInterval(4.0);
376 requestConfigForSet1.SetMaxAccuracy(1000.0); // accuracy
377 requestConfigForSet1.SetFixNumber(1);
378 requestConfigForCompare->Set(requestConfigForSet1);
379 EXPECT_NE("", requestConfigForCompare->ToString());
380 EXPECT_EQ(true, requestConfigForCompare->IsSame(requestConfigForSet1));
381
382 RequestConfig requestConfigForSet2;
383 requestConfigForSet2.SetScenario(2);
384 EXPECT_NE("", requestConfigForCompare->ToString());
385 EXPECT_EQ(false, requestConfigForCompare->IsSame(requestConfigForSet2));
386
387 RequestConfig requestConfigForSet3;
388 requestConfigForSet3.SetScenario(SCENE_UNSET);
389 requestConfigForSet3.SetPriority(2);
390 requestConfigForCompare->SetScenario(SCENE_UNSET);
391 EXPECT_NE("", requestConfigForCompare->ToString());
392 EXPECT_EQ(true, requestConfigForCompare->IsSame(requestConfigForSet3));
393
394 RequestConfig requestConfigForSet4;
395 requestConfigForSet4.SetScenario(SCENE_UNSET);
396 requestConfigForSet4.SetPriority(1);
397 requestConfigForCompare->SetScenario(SCENE_UNSET);
398 EXPECT_NE("", requestConfigForCompare->ToString());
399 EXPECT_EQ(false, requestConfigForCompare->IsSame(requestConfigForSet4));
400 LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest002 end");
401 }
402
403 /*
404 * @tc.name: GeocodingMockInfoTest001
405 * @tc.desc: read from parcel.
406 * @tc.type: FUNC
407 */
408 #ifdef FEATURE_GEOCODE_SUPPORT
409 HWTEST_F(LocationCommonTest, GeocodingMockInfoTest001, TestSize.Level1)
410 {
411 GTEST_LOG_(INFO)
412 << "LocationCommonTest, GeocodingMockInfoTest001, TestSize.Level1";
413 LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest001 begin");
414 MessageParcel parcel;
415 parcel.WriteString16(Str8ToStr16("locale"));
416 parcel.WriteDouble(12.0); // latitude
417 parcel.WriteDouble(13.0); // longitude
418 parcel.WriteInt32(1); // maxItems
419 std::unique_ptr<GeocodingMockInfo> mockInfo = std::make_unique<GeocodingMockInfo>();
420 mockInfo->ReadFromParcel(parcel);
421 std::shared_ptr<ReverseGeocodeRequest> reverseGeocodeRequest = mockInfo->GetLocation();
422 EXPECT_EQ(true, reverseGeocodeRequest != nullptr);
423 EXPECT_EQ("locale", reverseGeocodeRequest->locale);
424 EXPECT_EQ(12.0, reverseGeocodeRequest->latitude);
425 EXPECT_EQ(13.0, reverseGeocodeRequest->longitude);
426 EXPECT_EQ(1, reverseGeocodeRequest->maxItems);
427
428 MessageParcel newParcel;
429 mockInfo->Marshalling(newParcel);
430 EXPECT_EQ("locale", Str16ToStr8(newParcel.ReadString16()));
431 EXPECT_EQ(12.0, newParcel.ReadDouble());
432 EXPECT_EQ(13.0, newParcel.ReadDouble());
433 EXPECT_EQ(1, newParcel.ReadInt32());
434 GeocodingMockInfo::Unmarshalling(newParcel);
435 LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest001 end");
436 }
437 #endif
438
439 HWTEST_F(LocationCommonTest, AppIdentityTest001, TestSize.Level1)
440 {
441 GTEST_LOG_(INFO)
442 << "LocationCommonTest, AppIdentityTest001, TestSize.Level1";
443 LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest001 begin");
444 AppIdentity identity;
445 identity.SetPid(1);
446 identity.SetUid(2);
447 identity.SetTokenId(3);
448 identity.SetFirstTokenId(4);
449 identity.SetBundleName("bundleName");
450 EXPECT_EQ(1, identity.GetPid());
451 EXPECT_EQ(2, identity.GetUid());
452 EXPECT_EQ(3, identity.GetTokenId());
453 EXPECT_EQ(4, identity.GetFirstTokenId());
454 EXPECT_EQ("bundleName", identity.GetBundleName());
455 EXPECT_NE("", identity.ToString());
456 LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest001 end");
457 }
458
459 #ifdef FEATURE_GEOCODE_SUPPORT
460 HWTEST_F(LocationCommonTest, GeocodingMockInfoTest002, TestSize.Level1)
461 {
462 GTEST_LOG_(INFO)
463 << "LocationCommonTest, GeocodingMockInfoTest002, TestSize.Level1";
464 LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest002 begin");
465 std::unique_ptr<GeocodingMockInfo> mockInfo = std::make_unique<GeocodingMockInfo>();
466
467 auto reverseGeocodeRequest = std::make_shared<ReverseGeocodeRequest>();
468 mockInfo->SetLocation(reverseGeocodeRequest);
469 EXPECT_NE(nullptr, mockInfo->GetLocation());
470
471 std::shared_ptr<GeoAddress> geoAddress = std::make_shared<GeoAddress>();
472 mockInfo->SetGeoAddressInfo(geoAddress);
473 EXPECT_NE(nullptr, mockInfo->GetGeoAddressInfo());
474 LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest002 end");
475 }
476 #endif
477
478 HWTEST_F(LocationCommonTest, PermStateChangeCallbackTest001, TestSize.Level1)
479 {
480 GTEST_LOG_(INFO)
481 << "LocationCommonTest, PermStateChangeCallbackTest001, TestSize.Level1";
482 LBSLOGI(LOCATOR, "[LocationCommonTest] PermStateChangeCallbackTest001 begin");
483 uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
484 PermStateChangeScope scopeInfo;
485 scopeInfo.permList = {"ohos.permission.LOCATION"};
486 scopeInfo.tokenIDs = {callingTokenId};
487 auto callbackPtr = std::make_shared<PermissionStatusChangeCb>(scopeInfo);
488 struct PermStateChangeInfo result{0, callingTokenId, ACCESS_LOCATION};
489 ASSERT_TRUE(callbackPtr != nullptr);
490 callbackPtr->PermStateChangeCallback(result);
491 LBSLOGI(LOCATOR, "[LocationCommonTest] PermStateChangeCallbackTest001 end");
492 }
493
494 HWTEST_F(LocationCommonTest, LocatorEventSubscriberTest001, TestSize.Level1)
495 {
496 GTEST_LOG_(INFO)
497 << "LocationCommonTest, LocatorEventSubscriberTest001, TestSize.Level1";
498 LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest001 begin");
499 OHOS::EventFwk::MatchingSkills matchingSkills;
500 matchingSkills.AddEvent(MODE_CHANGED_EVENT);
501 OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
502 auto locatorEventSubscriber = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
503 Want want;
504 want.SetAction("usual.event.location.MODE_STATE_CHANGED");
505 OHOS::EventFwk::CommonEventData data;
506 data.SetWant(want);
507 ASSERT_TRUE(locatorEventSubscriber != nullptr);
508 locatorEventSubscriber->OnReceiveEvent(data);
509 LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest001 end");
510 }
511
512 HWTEST_F(LocationCommonTest, LocatorEventSubscriberTest002, TestSize.Level1)
513 {
514 GTEST_LOG_(INFO)
515 << "LocationCommonTest, LocatorEventSubscriberTest002, TestSize.Level1";
516 LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest002 begin");
517 OHOS::EventFwk::MatchingSkills matchingSkills;
518 matchingSkills.AddEvent(MODE_CHANGED_EVENT);
519 OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
520 auto locatorEventSubscriber = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
521 Want want;
522 want.SetAction("Invalid action");
523 OHOS::EventFwk::CommonEventData data;
524 data.SetWant(want);
525 ASSERT_TRUE(locatorEventSubscriber != nullptr);
526 locatorEventSubscriber->OnReceiveEvent(data);
527 LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest002 end");
528 }
529
530 #ifdef FEATURE_GEOCODE_SUPPORT
531 HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest001, TestSize.Level1)
532 {
533 GTEST_LOG_(INFO)
534 << "LocationCommonTest, GeoAddressDescriptionsTest001, TestSize.Level1";
535 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest001 begin");
536 std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
537 SetGeoAddress(geoAddress);
538 EXPECT_EQ("line", geoAddress->GetDescriptions(0));
539 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest001 end");
540 }
541 #endif
542
543 #ifdef FEATURE_GEOCODE_SUPPORT
544 HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest002, TestSize.Level1)
545 {
546 GTEST_LOG_(INFO)
547 << "LocationCommonTest, GeoAddressDescriptionsTest002, TestSize.Level1";
548 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest002 begin");
549 std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
550 SetGeoAddress(geoAddress);
551 EXPECT_EQ("", geoAddress->GetDescriptions(1));
552 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest002 end");
553 }
554 #endif
555
556 #ifdef FEATURE_GEOCODE_SUPPORT
557 HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest003, TestSize.Level1)
558 {
559 GTEST_LOG_(INFO)
560 << "LocationCommonTest, GeoAddressDescriptionsTest003, TestSize.Level1";
561 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest003 begin");
562 std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
563 SetGeoAddress(geoAddress);
564 EXPECT_EQ("", geoAddress->GetDescriptions(-1));
565 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest003 end");
566 }
567 #endif
568
569 HWTEST_F(LocationCommonTest, LoadLocationSaTest001, TestSize.Level1)
570 {
571 GTEST_LOG_(INFO)
572 << "LocationCommonTest, LoadLocationSaTest001, TestSize.Level1";
573 LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest001 begin");
574 LocationErrCode err = LocationSaLoadManager::GetInstance()->LoadLocationSa(UN_SAID);
575 EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
576
577 err = LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_LOCATOR_SA_ID);
578 LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest001 end");
579 }
580
581 HWTEST_F(LocationCommonTest, LoadLocationSaTest002, TestSize.Level1)
582 {
583 GTEST_LOG_(INFO)
584 << "LocationCommonTest, LoadLocationSaTest002, TestSize.Level1";
585 LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest002 begin");
586 LocationErrCode err = LocationSaLoadManager::GetInstance()->UnloadLocationSa(UN_SAID);
587 EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
588
589 // can not unload sa by another sa
590 err = LocationSaLoadManager::GetInstance()->UnloadLocationSa(LOCATION_NOPOWER_LOCATING_SA_ID);
591 EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
592 LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest002 end");
593 }
594
595 HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest001, TestSize.Level1)
596 {
597 GTEST_LOG_(INFO)
598 << "LocationCommonTest, LocationDataRdbHelperTest001, TestSize.Level1";
599 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest001 begin");
600
601 Uri unknownUri(UN_URI);
602 auto dataRdbObserver = sptr<LocationDataRdbObserver>(new (std::nothrow) LocationDataRdbObserver());
603 LocationErrCode err =
604 LocationDataRdbHelper::GetInstance()->RegisterDataObserver(unknownUri, dataRdbObserver);
605 EXPECT_EQ(ERRCODE_SUCCESS, err);
606
607 err = LocationDataRdbHelper::GetInstance()->UnregisterDataObserver(unknownUri, dataRdbObserver);
608 EXPECT_EQ(ERRCODE_SUCCESS, err);
609 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest001 end");
610 }
611
612 HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest002, TestSize.Level1)
613 {
614 GTEST_LOG_(INFO)
615 << "LocationCommonTest, LocationDataRdbHelperTest002, TestSize.Level1";
616 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest002 begin");
617 Uri locationDataEnableUri(LocationDataRdbManager::GetLocationDataUriByCurrentUserId("location_enable"));
618 int32_t state = DISABLED;
619 LocationDataRdbHelper::GetInstance()->SetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state);
620 LocationDataRdbHelper::GetInstance()->GetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state);
621 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest002 end");
622 }
623
624 HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest003, TestSize.Level1)
625 {
626 GTEST_LOG_(INFO)
627 << "LocationCommonTest, LocationDataRdbHelperTest003, TestSize.Level1";
628 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest003 begin");
629 Uri unknownUri(UN_URI);
630 int32_t state = DISABLED;
631 LocationDataRdbHelper::GetInstance()->SetValue(unknownUri, LOCATION_DATA_COLUMN_ENABLE, state);
632
633 EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, LocationDataRdbHelper::GetInstance()->
634 GetValue(unknownUri, LOCATION_DATA_COLUMN_ENABLE, state));
635 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest003 end");
636 }
637
638 HWTEST_F(LocationCommonTest, LocationSaLoadManager002, TestSize.Level1)
639 {
640 GTEST_LOG_(INFO)
641 << "LocationCommonTest, LocationSaLoadManager002, TestSize.Level1";
642 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationSaLoadManager002 begin");
643 LocationSaLoadManager::GetInstance()->LoadSystemAbilityFail();
644
645 auto locationSaLoadCallback = sptr<LocationSaLoadCallback>(new LocationSaLoadCallback());
646 ASSERT_TRUE(locationSaLoadCallback != nullptr);
647 locationSaLoadCallback->OnLoadSystemAbilityFail(0);
648 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationSaLoadManager002 end");
649 }
650
651 HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest004, TestSize.Level1)
652 {
653 GTEST_LOG_(INFO)
654 << "LocationCommonTest, GeoAddressDescriptionsTest004, TestSize.Level1";
655 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest004 begin");
656 std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
657 geoAddress->descriptionsSize_ = 1;
658 EXPECT_EQ("", geoAddress->GetDescriptions(-1));
659 LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest004 end");
660 }
661
662 HWTEST_F(LocationCommonTest, LocationTest002, TestSize.Level1)
663 {
664 GTEST_LOG_(INFO)
665 << "LocationCommonTest, LocationTest002, TestSize.Level1";
666 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest002 begin");
667 auto location = std::make_shared<Location>();
668 location->SetLatitude(VERIFY_LOCATION_LATITUDE);
669 location->SetLongitude(VERIFY_LOCATION_LONGITUDE);
670 location->SetAltitude(VERIFY_LOCATION_ALTITUDE);
671 location->SetAccuracy(VERIFY_LOCATION_ACCURACY);
672 location->SetSpeed(VERIFY_LOCATION_SPEED);
673 location->SetDirection(VERIFY_LOCATION_DIRECTION);
674 location->SetTimeStamp(VERIFY_LOCATION_TIME);
675 location->SetTimeSinceBoot(VERIFY_LOCATION_TIMESINCEBOOT);
676 std::vector<std::string> additions;
677 additions.push_back("additions");
678 location->SetAdditions(additions, false);
679 location->SetAdditionSize(1);
680 location->SetIsFromMock(1);
681 location->ToString();
682 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest002 end");
683 }
684
685 HWTEST_F(LocationCommonTest, AppIdentityTest002, TestSize.Level1)
686 {
687 GTEST_LOG_(INFO)
688 << "LocationCommonTest, AppIdentityTest002, TestSize.Level1";
689 LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest002 begin");
690 AppIdentity identity(1, 2, 3, 4, 5);
691 LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest002 end");
692 }
693
694 HWTEST_F(LocationCommonTest, RequestConfigTest003, TestSize.Level1)
695 {
696 GTEST_LOG_(INFO)
697 << "LocationCommonTest, RequestConfigTest003, TestSize.Level1";
698 LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest003 begin");
699 std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>(1);
700 ASSERT_TRUE(requestConfig != nullptr);
701 LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest003 end");
702 }
703
704 #define LOCATION_LOADSA_TIMEOUT_MS_FOR_TEST = 0
705 #define LOCATION_LOADSA_TIMEOUT_MS LOCATION_LOADSA_TIMEOUT_MS_FOR_TEST
706 HWTEST_F(LocationCommonTest, LoadLocationSaTest003, TestSize.Level1)
707 {
708 GTEST_LOG_(INFO)
709 << "LocationCommonTest, LoadLocationSaTest003, TestSize.Level1";
710 LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest003 begin");
711 LocationErrCode err =
712 LocationSaLoadManager::GetInstance()->WaitLoadStateChange(LOCATION_LOCATOR_SA_ID);
713 EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
714 LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest003 end");
715 }
716 #undef LOCATION_LOADSA_TIMEOUT_MS
717 #undef LOCATION_LOADSA_TIMEOUT_MS_FOR_TEST
718
OhosHookTest01(const HOOK_INFO * hookInfo,void * executionContext)719 static int OhosHookTest01(const HOOK_INFO *hookInfo, void *executionContext)
720 {
721 LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
722 EXPECT_NE(hookInfo, nullptr);
723 EXPECT_EQ(hookInfo->prio, 0);
724 EXPECT_EQ(executionContext, nullptr);
725 return 0;
726 }
727
OhosHookTest02(const HOOK_INFO * hookInfo,void * executionContext)728 static int OhosHookTest02(const HOOK_INFO *hookInfo, void *executionContext)
729 {
730 LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
731 EXPECT_NE(hookInfo, nullptr);
732 EXPECT_EQ(hookInfo->prio, 1);
733 EXPECT_EQ(executionContext, nullptr);
734 return 0;
735 }
736
737 typedef struct hookTestStruct {
738 const char *hookTestName;
739 LocationProcessStage state;
740 } HOOK_TEST;
741
OhosHookTest03(const HOOK_INFO * hookInfo,void * executionContext)742 static int OhosHookTest03(const HOOK_INFO *hookInfo, void *executionContext)
743 {
744 LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
745 EXPECT_NE(hookInfo, nullptr);
746 EXPECT_EQ(hookInfo->prio, 0);
747
748 EXPECT_NE(executionContext, nullptr);
749 HOOK_TEST* hookTest = (HOOK_TEST*)executionContext;
750 EXPECT_NE(hookTest, nullptr);
751 LocationProcessStage state = hookTest->state;
752 const char *hookTestName = hookTest->hookTestName;
753 EXPECT_EQ(state, LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS);
754 EXPECT_EQ(hookTestName, "HookUtils002");
755 return 0;
756 }
757
OhosHookTest04(const HOOK_INFO * hookInfo,void * executionContext)758 static int OhosHookTest04(const HOOK_INFO *hookInfo, void *executionContext)
759 {
760 LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
761 EXPECT_NE(hookInfo, nullptr);
762 EXPECT_EQ(hookInfo->prio, 1);
763
764 EXPECT_NE(executionContext, nullptr);
765 HOOK_TEST* hookTest = (HOOK_TEST*)executionContext;
766 EXPECT_NE(hookTest, nullptr);
767 LocationProcessStage state = hookTest->state;
768 const char *hookTestName = hookTest->hookTestName;
769 EXPECT_EQ(state, LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS);
770 EXPECT_EQ(hookTestName, "HookUtils002");
771 return 0;
772 }
773
774 HWTEST_F(LocationCommonTest, HookUtils001, TestSize.Level1)
775 {
776 GTEST_LOG_(INFO)
777 << "LocationCommonTest, HookUtils001, TestSize.Level1";
778 LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils001 begin");
779 ASSERT_TRUE(HookUtils::GetLocationExtHookMgr() != nullptr);
780 EXPECT_EQ(ERRCODE_SUCCESS,
781 HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, 0, OhosHookTest01));
782 EXPECT_EQ(ERRCODE_SUCCESS,
783 HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, 1, OhosHookTest02));
784
785 EXPECT_EQ(ERRCODE_SUCCESS,
786 HookUtils::ExecuteHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, nullptr, nullptr));
787
788 HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, OhosHookTest01);
789 HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, OhosHookTest02);
790 LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils001 end");
791 }
792
793 HWTEST_F(LocationCommonTest, HookUtils002, TestSize.Level1)
794 {
795 GTEST_LOG_(INFO)
796 << "LocationCommonTest, HookUtils002, TestSize.Level1";
797 LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils002 begin");
798 ASSERT_TRUE(HookUtils::GetLocationExtHookMgr() != nullptr);
799 EXPECT_EQ(ERRCODE_SUCCESS,
800 HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, 0, OhosHookTest03));
801 EXPECT_EQ(ERRCODE_SUCCESS,
802 HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, 1, OhosHookTest04));
803
804 HOOK_TEST hookTestStruct;
805 hookTestStruct.hookTestName = "HookUtils002";
806 hookTestStruct.state = LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS;
807
808 EXPECT_EQ(ERRCODE_SUCCESS,
809 HookUtils::ExecuteHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, (void *)(&hookTestStruct), nullptr));
810 HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, OhosHookTest03);
811 HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, OhosHookTest04);
812 LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils002 end");
813 }
814
815 HWTEST_F(LocationCommonTest, Request001, TestSize.Level1)
816 {
817 GTEST_LOG_(INFO)
818 << "LocationCommonTest, Request001, TestSize.Level1";
819 LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 begin");
820 std::unique_ptr<Request> request = std::make_unique<Request>();
821 request->requestConfig_ = nullptr;
822 RequestConfig requestConfig;
823 request->SetRequestConfig(requestConfig);
824 LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 end");
825 }
826
827 HWTEST_F(LocationCommonTest, Request002, TestSize.Level1)
828 {
829 GTEST_LOG_(INFO)
830 << "LocationCommonTest, Request002, TestSize.Level1";
831 LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 begin");
832 std::unique_ptr<Request> request = std::make_unique<Request>();
833 int type = 1;
834 request->SetPermUsedType(type);
835 LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 end");
836 }
837
838 HWTEST_F(LocationCommonTest, Request003, TestSize.Level1)
839 {
840 GTEST_LOG_(INFO)
841 << "LocationCommonTest, Request003, TestSize.Level1";
842 LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 begin");
843 std::unique_ptr<Request> request = std::make_unique<Request>();
844 std::shared_ptr<std::list<std::string>> proxys;
845 proxys = nullptr;
846 request->GetProxyName(proxys);
847 LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 end");
848 }
849
850 HWTEST_F(LocationCommonTest, Request004, TestSize.Level1)
851 {
852 GTEST_LOG_(INFO)
853 << "LocationCommonTest, Request004, TestSize.Level1";
854 LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 begin");
855 std::unique_ptr<Request> request = std::make_unique<Request>();
856 request->requestConfig_ = nullptr;
857 std::shared_ptr<std::list<std::string>> proxys;
858 request->GetProxyName(proxys);
859 LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 end");
860 }
861
862 HWTEST_F(LocationCommonTest, Request005, TestSize.Level1)
863 {
864 GTEST_LOG_(INFO)
865 << "LocationCommonTest, Request005, TestSize.Level1";
866 LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 begin");
867 std::unique_ptr<Request> request = std::make_unique<Request>();
868 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
869 request->GetProxyName(proxys);
870 LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 end");
871 }
872
873 HWTEST_F(LocationCommonTest, Request006, TestSize.Level1)
874 {
875 GTEST_LOG_(INFO)
876 << "LocationCommonTest, Request006, TestSize.Level1";
877 LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 begin");
878 std::unique_ptr<Request> request = std::make_unique<Request>();
879 request->requestConfig_ = nullptr;
880 std::shared_ptr<std::list<std::string>> proxys;
881 proxys = nullptr;
882 request->GetProxyName(proxys);
883 LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 end");
884 }
885
886 HWTEST_F(LocationCommonTest, Request007, TestSize.Level1)
887 {
888 GTEST_LOG_(INFO)
889 << "LocationCommonTest, Request007, TestSize.Level1";
890 LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 begin");
891 std::unique_ptr<Request> request = std::make_unique<Request>();
892 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
893 request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION;
894 request->GetProxyName(proxys);
895 request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT;
896 request->GetProxyName(proxys);
897 request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT;
898 request->GetProxyName(proxys);
899 request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION;
900 request->GetProxyName(proxys);
901 request->requestConfig_->scenario_ = SCENE_NAVIGATION;
902 request->GetProxyName(proxys);
903 request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING;
904 request->GetProxyName(proxys);
905 request->requestConfig_->scenario_ = LOCATION_SCENE_LOW_POWER_CONSUMPTION;
906 request->GetProxyName(proxys);
907 request->requestConfig_->scenario_ = LOCATION_SCENE_DAILY_LIFE_SERVICE;
908 request->GetProxyName(proxys);
909 request->requestConfig_->scenario_ = SCENE_DAILY_LIFE_SERVICE;
910 request->GetProxyName(proxys);
911 request->requestConfig_->scenario_ = LOCATION_SCENE_NO_POWER_CONSUMPTION;
912 request->GetProxyName(proxys);
913 request->requestConfig_->scenario_ = SCENE_NO_POWER;
914 request->GetProxyName(proxys);
915 request->requestConfig_->scenario_ = SCENE_UNSET;
916 request->GetProxyName(proxys);
917 request->requestConfig_->scenario_ = 0;
918 request->GetProxyName(proxys);
919 LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 end");
920 }
921
922 HWTEST_F(LocationCommonTest, Request008, TestSize.Level1)
923 {
924 GTEST_LOG_(INFO)
925 << "LocationCommonTest, Request008, TestSize.Level1";
926 LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 begin");
927 std::unique_ptr<Request> request = std::make_unique<Request>();
928 request->requestConfig_ = nullptr;
929 request->ToString();
930 LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 end");
931 }
932
933 HWTEST_F(LocationCommonTest, Request009, TestSize.Level1)
934 {
935 GTEST_LOG_(INFO)
936 << "LocationCommonTest, Request009, TestSize.Level1";
937 LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin");
938 std::unique_ptr<Request> request = std::make_unique<Request>();
939 request->requestConfig_->scenario_ = SCENE_NAVIGATION;
940 request->SetNlpRequestType();
941 request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING;
942 request->SetNlpRequestType();
943 request->requestConfig_->scenario_ = SCENE_CAR_HAILING;
944 request->SetNlpRequestType();
945 request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION;
946 request->SetNlpRequestType();
947 request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT;
948 request->SetNlpRequestType();
949 request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT;
950 request->SetNlpRequestType();
951 request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION;
952 request->SetNlpRequestType();
953 request->requestConfig_->priority_ = PRIORITY_ACCURACY;
954 request->SetNlpRequestType();
955 request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX;
956 request->SetNlpRequestType();
957 request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY;
958 request->SetNlpRequestType();
959 request->requestConfig_->priority_ = 0;
960 request->SetNlpRequestType();
961 request->requestConfig_->scenario_ = 0;
962 request->SetNlpRequestType();
963 LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 end");
964 }
965
966 HWTEST_F(LocationCommonTest, Request010, TestSize.Level1)
967 {
968 GTEST_LOG_(INFO)
969 << "LocationCommonTest, Request009, TestSize.Level1";
970 LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin");
971 std::unique_ptr<Request> request = std::make_unique<Request>();
972 request->lastLocation_ = nullptr;
973 const std::unique_ptr<Location> location;
974 request->SetLastLocation(location);
975 LBSLOGI(LOCATOR, "[LocationCommonTest] Request010 end");
976 }
977
978 HWTEST_F(LocationCommonTest, Request011, TestSize.Level1)
979 {
980 GTEST_LOG_(INFO)
981 << "LocationCommonTest, Request011, TestSize.Level1";
982 LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 begin");
983 std::unique_ptr<Request> request = std::make_unique<Request>();
984 std::shared_ptr<std::list<std::string>> proxys;
985 proxys = nullptr;
986 request->GetProxyNameByPriority(proxys);
987 LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 end");
988 }
989
990 HWTEST_F(LocationCommonTest, Request012, TestSize.Level1)
991 {
992 GTEST_LOG_(INFO)
993 << "LocationCommonTest, Request012, TestSize.Level1";
994 LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 begin");
995 std::unique_ptr<Request> request = std::make_unique<Request>();
996 request->requestConfig_ = nullptr;
997 std::shared_ptr<std::list<std::string>> proxys;
998 proxys = nullptr;
999 request->GetProxyNameByPriority(proxys);
1000 LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 end");
1001 }
1002
1003 HWTEST_F(LocationCommonTest, Request013, TestSize.Level1)
1004 {
1005 GTEST_LOG_(INFO)
1006 << "LocationCommonTest, Request013, TestSize.Level1";
1007 LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 begin");
1008 std::unique_ptr<Request> request = std::make_unique<Request>();
1009 request->requestConfig_ = nullptr;
1010 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
1011 request->GetProxyNameByPriority(proxys);
1012 LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 end");
1013 }
1014
1015 HWTEST_F(LocationCommonTest, Request014, TestSize.Level1)
1016 {
1017 GTEST_LOG_(INFO)
1018 << "LocationCommonTest, Request014, TestSize.Level1";
1019 LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 begin");
1020 std::unique_ptr<Request> request = std::make_unique<Request>();
1021 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
1022 request->requestConfig_->priority_ = PRIORITY_LOW_POWER;
1023 request->GetProxyName(proxys);
1024 request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY;
1025 request->GetProxyName(proxys);
1026 request->requestConfig_->priority_ = LOCATION_PRIORITY_LOCATING_SPEED;
1027 request->GetProxyName(proxys);
1028 request->requestConfig_->priority_ = PRIORITY_ACCURACY;
1029 request->GetProxyName(proxys);
1030 request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX;
1031 request->GetProxyName(proxys);
1032 request->requestConfig_->priority_ = 0;
1033 request->GetProxyName(proxys);
1034 LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 end");
1035 }
1036
1037 HWTEST_F(LocationCommonTest, Request015, TestSize.Level1)
1038 {
1039 GTEST_LOG_(INFO)
1040 << "LocationCommonTest, Request015, TestSize.Level1";
1041 LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 begin");
1042 std::unique_ptr<Request> request = std::make_unique<Request>();
1043 request->GetLocationPermState();
1044 request->GetBackgroundPermState();
1045 bool state = true;
1046 request->SetLocationPermState(state);
1047 request->SetBackgroundPermState(state);
1048 request->SetApproximatelyPermState(state);
1049 sptr<ILocatorCallback> callback;
1050 request->SetLocationErrorCallBack(callback);
1051 LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 end");
1052 }
1053
1054 HWTEST_F(LocationCommonTest, Location001, TestSize.Level1)
1055 {
1056 GTEST_LOG_(INFO)
1057 << "LocationCommonTest, Location001, TestSize.Level1";
1058 LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 begin");
1059 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1060 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1061 location2->latitude_ = MIN_LATITUDE + 1;
1062 location1->LocationEqual(location2);
1063 location2->latitude_ = MIN_LATITUDE - 1;
1064 location2->longitude_ = MIN_LONGITUDE + 1;
1065 location1->LocationEqual(location2);
1066 location2->longitude_ = MIN_LONGITUDE - 1;
1067 location2->altitude_ = 1.0;
1068 location1->LocationEqual(location2);
1069 location2->altitude_ = 0.0;
1070 location2->accuracy_ = 1.0;
1071 location1->LocationEqual(location2);
1072 location2->accuracy_ = 0.0;
1073 location2->speed_ = 1.0;
1074 location1->LocationEqual(location2);
1075 location2->speed_ = 0.0;
1076 location2->direction_ = 1.0;
1077 location1->LocationEqual(location2);
1078 location2->direction_ = 0.0;
1079 location2->timeStamp_ = 1;
1080 location1->LocationEqual(location2);
1081 location2->timeStamp_ = 0;
1082 location2->timeSinceBoot_ = 1;
1083 location1->LocationEqual(location2);
1084 location2->timeSinceBoot_ = 0;
1085 std::vector<std::string> additions;
1086 location2->additions_ = additions;
1087 location2->additionSize_ = 1;
1088 location1->LocationEqual(location2);
1089 location2->additionSize_ = 0;
1090 location2->isFromMock_ = true;
1091 location1->LocationEqual(location2);
1092 location2->isFromMock_ = false;
1093 location1->LocationEqual(location2);
1094 LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 end");
1095 }
1096
1097 HWTEST_F(LocationCommonTest, Location002, TestSize.Level1)
1098 {
1099 GTEST_LOG_(INFO)
1100 << "LocationCommonTest, Location002, TestSize.Level1";
1101 LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 begin");
1102 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1103 std::unique_ptr<Location> location2 = nullptr;
1104 location1->LocationEqual(location2);
1105 LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 end");
1106 }
1107
1108 HWTEST_F(LocationCommonTest, Location003, TestSize.Level1)
1109 {
1110 GTEST_LOG_(INFO)
1111 << "LocationCommonTest, Location003, TestSize.Level1";
1112 LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 begin");
1113 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1114 std::unique_ptr<Location> location2 = nullptr;
1115 location1->AdditionEqual(location2);
1116 LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 end");
1117 }
1118
1119 HWTEST_F(LocationCommonTest, Location004, TestSize.Level1)
1120 {
1121 GTEST_LOG_(INFO)
1122 << "LocationCommonTest, Location004, TestSize.Level1";
1123 LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 begin");
1124 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1125 std::vector<std::string> additions;
1126 location1->additions_ = additions;
1127 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1128 location2->additions_ = additions;
1129 location1->AdditionEqual(location2);
1130 LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 end");
1131 }
1132
1133 HWTEST_F(LocationCommonTest, Location005, TestSize.Level1)
1134 {
1135 GTEST_LOG_(INFO)
1136 << "LocationCommonTest, Location005, TestSize.Level1";
1137 LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 begin");
1138 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1139 std::vector<std::string> additions;
1140 location1->additions_ = additions;
1141 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1142 additions.resize(5);
1143 location2->additions_ = additions;
1144 location1->AdditionEqual(location2);
1145 LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 end");
1146 }
1147
1148 HWTEST_F(LocationCommonTest, Location006, TestSize.Level1)
1149 {
1150 GTEST_LOG_(INFO)
1151 << "LocationCommonTest, Location006, TestSize.Level1";
1152 LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 begin");
1153 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1154 std::vector<std::string> additions1(4, "1");
1155 location1->additions_ = additions1;
1156 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1157 std::vector<std::string> additions2(4, "2");
1158 location2->additions_ = additions2;
1159 location1->AdditionEqual(location2);
1160 LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 end");
1161 }
1162
1163 HWTEST_F(LocationCommonTest, LbsResLoader001, TestSize.Level1)
1164 {
1165 GTEST_LOG_(INFO)
1166 << "LocationCommonTest, LbsResLoader001, TestSize.Level1";
1167 LBSLOGI(LOCATOR, "[LocationCommonTest] LbsResLoader001 begin");
1168 LbsResLoader resLoader;
1169 std::string countryCodeStr8 = resLoader.GetSystemRegion();
1170 countryCodeStr8 = resLoader.GetSystemRegion();
1171 EXPECT_NE(countryCodeStr8, "");
1172 LBSLOGI(LOCATOR, "[LocationCommonTest] LbsResLoader001 end");
1173 }
1174
1175 HWTEST_F(LocationCommonTest, LocationDataRdbManagerTest001, TestSize.Level1)
1176 {
1177 GTEST_LOG_(INFO)
1178 << "LocationCommonTest, LocationDataRdbManagerTest001, TestSize.Level1";
1179 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest001 begin");
1180 std::string state;
1181 bool ret =
1182 LocationDataRdbManager::GetIntelligentStatus("testuri", "testuri", "testColName", state);
1183 EXPECT_EQ(false, ret);
1184 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest001 end");
1185 }
1186
1187 HWTEST_F(LocationCommonTest, LocationDataRdbManagerTest002, TestSize.Level1)
1188 {
1189 GTEST_LOG_(INFO)
1190 << "LocationCommonTest, LocationDataRdbManagerTest002, TestSize.Level1";
1191 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest002 begin");
1192 std::string state;
1193 bool ret =
1194 LocationDataRdbManager::SetGnssSessionState(0, "testuri", "testColName");
1195 EXPECT_EQ(false, ret);
1196 LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest002 end");
1197 }
1198 } // namespace Location
1199 } // namespace OHOS
1200