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