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 "work_record_statistic.h"
60 #include "permission_manager.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.Level1)
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.Level1)
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, WorkRecordStatistic001, TestSize.Level1)
816 {
817 GTEST_LOG_(INFO)
818 << "LocationCommonTest, WorkRecordStatistic001, TestSize.Level1";
819 LBSLOGI(LOCATOR, "[LocationCommonTest] WorkRecordStatistic001 begin");
820 auto workRecordStatistic = WorkRecordStatistic::GetInstance();
821 workRecordStatistic->Update("network", 1);
822 LBSLOGI(LOCATOR, "[LocationCommonTest] WorkRecordStatistic001 end");
823 }
824
825 HWTEST_F(LocationCommonTest, Request001, TestSize.Level1)
826 {
827 GTEST_LOG_(INFO)
828 << "LocationCommonTest, Request001, TestSize.Level1";
829 LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 begin");
830 std::unique_ptr<Request> request = std::make_unique<Request>();
831 request->requestConfig_ = nullptr;
832 RequestConfig requestConfig;
833 request->SetRequestConfig(requestConfig);
834 LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 end");
835 }
836
837 HWTEST_F(LocationCommonTest, Request002, TestSize.Level1)
838 {
839 GTEST_LOG_(INFO)
840 << "LocationCommonTest, Request002, TestSize.Level1";
841 LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 begin");
842 std::unique_ptr<Request> request = std::make_unique<Request>();
843 int type = 1;
844 request->SetPermUsedType(type);
845 LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 end");
846 }
847
848 HWTEST_F(LocationCommonTest, Request003, TestSize.Level1)
849 {
850 GTEST_LOG_(INFO)
851 << "LocationCommonTest, Request003, TestSize.Level1";
852 LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 begin");
853 std::unique_ptr<Request> request = std::make_unique<Request>();
854 std::shared_ptr<std::list<std::string>> proxys;
855 proxys = nullptr;
856 request->GetProxyName(proxys);
857 LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 end");
858 }
859
860 HWTEST_F(LocationCommonTest, Request004, TestSize.Level1)
861 {
862 GTEST_LOG_(INFO)
863 << "LocationCommonTest, Request004, TestSize.Level1";
864 LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 begin");
865 std::unique_ptr<Request> request = std::make_unique<Request>();
866 request->requestConfig_ = nullptr;
867 std::shared_ptr<std::list<std::string>> proxys;
868 request->GetProxyName(proxys);
869 LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 end");
870 }
871
872 HWTEST_F(LocationCommonTest, Request005, TestSize.Level1)
873 {
874 GTEST_LOG_(INFO)
875 << "LocationCommonTest, Request005, TestSize.Level1";
876 LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 begin");
877 std::unique_ptr<Request> request = std::make_unique<Request>();
878 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
879 request->GetProxyName(proxys);
880 LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 end");
881 }
882
883 HWTEST_F(LocationCommonTest, Request006, TestSize.Level1)
884 {
885 GTEST_LOG_(INFO)
886 << "LocationCommonTest, Request006, TestSize.Level1";
887 LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 begin");
888 std::unique_ptr<Request> request = std::make_unique<Request>();
889 request->requestConfig_ = nullptr;
890 std::shared_ptr<std::list<std::string>> proxys;
891 proxys = nullptr;
892 request->GetProxyName(proxys);
893 LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 end");
894 }
895
896 HWTEST_F(LocationCommonTest, Request007, TestSize.Level1)
897 {
898 GTEST_LOG_(INFO)
899 << "LocationCommonTest, Request007, TestSize.Level1";
900 LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 begin");
901 std::unique_ptr<Request> request = std::make_unique<Request>();
902 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
903 request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION;
904 request->GetProxyName(proxys);
905 request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT;
906 request->GetProxyName(proxys);
907 request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT;
908 request->GetProxyName(proxys);
909 request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION;
910 request->GetProxyName(proxys);
911 request->requestConfig_->scenario_ = SCENE_NAVIGATION;
912 request->GetProxyName(proxys);
913 request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING;
914 request->GetProxyName(proxys);
915 request->requestConfig_->scenario_ = LOCATION_SCENE_LOW_POWER_CONSUMPTION;
916 request->GetProxyName(proxys);
917 request->requestConfig_->scenario_ = LOCATION_SCENE_DAILY_LIFE_SERVICE;
918 request->GetProxyName(proxys);
919 request->requestConfig_->scenario_ = SCENE_DAILY_LIFE_SERVICE;
920 request->GetProxyName(proxys);
921 request->requestConfig_->scenario_ = LOCATION_SCENE_NO_POWER_CONSUMPTION;
922 request->GetProxyName(proxys);
923 request->requestConfig_->scenario_ = SCENE_NO_POWER;
924 request->GetProxyName(proxys);
925 request->requestConfig_->scenario_ = SCENE_UNSET;
926 request->GetProxyName(proxys);
927 request->requestConfig_->scenario_ = 0;
928 request->GetProxyName(proxys);
929 LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 end");
930 }
931
932 HWTEST_F(LocationCommonTest, Request008, TestSize.Level1)
933 {
934 GTEST_LOG_(INFO)
935 << "LocationCommonTest, Request008, TestSize.Level1";
936 LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 begin");
937 std::unique_ptr<Request> request = std::make_unique<Request>();
938 request->requestConfig_ = nullptr;
939 request->ToString();
940 LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 end");
941 }
942
943 HWTEST_F(LocationCommonTest, Request009, TestSize.Level1)
944 {
945 GTEST_LOG_(INFO)
946 << "LocationCommonTest, Request009, TestSize.Level1";
947 LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin");
948 std::unique_ptr<Request> request = std::make_unique<Request>();
949 request->requestConfig_->scenario_ = SCENE_NAVIGATION;
950 request->SetNlpRequestType();
951 request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING;
952 request->SetNlpRequestType();
953 request->requestConfig_->scenario_ = SCENE_CAR_HAILING;
954 request->SetNlpRequestType();
955 request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION;
956 request->SetNlpRequestType();
957 request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT;
958 request->SetNlpRequestType();
959 request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT;
960 request->SetNlpRequestType();
961 request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION;
962 request->SetNlpRequestType();
963 request->requestConfig_->priority_ = PRIORITY_ACCURACY;
964 request->SetNlpRequestType();
965 request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX;
966 request->SetNlpRequestType();
967 request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY;
968 request->SetNlpRequestType();
969 request->requestConfig_->priority_ = 0;
970 request->SetNlpRequestType();
971 request->requestConfig_->scenario_ = 0;
972 request->SetNlpRequestType();
973 LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 end");
974 }
975
976 HWTEST_F(LocationCommonTest, Request010, TestSize.Level1)
977 {
978 GTEST_LOG_(INFO)
979 << "LocationCommonTest, Request009, TestSize.Level1";
980 LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin");
981 std::unique_ptr<Request> request = std::make_unique<Request>();
982 request->lastLocation_ = nullptr;
983 const std::unique_ptr<Location> location;
984 request->SetLastLocation(location);
985 LBSLOGI(LOCATOR, "[LocationCommonTest] Request010 end");
986 }
987
988 HWTEST_F(LocationCommonTest, Request011, TestSize.Level1)
989 {
990 GTEST_LOG_(INFO)
991 << "LocationCommonTest, Request011, TestSize.Level1";
992 LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 begin");
993 std::unique_ptr<Request> request = std::make_unique<Request>();
994 std::shared_ptr<std::list<std::string>> proxys;
995 proxys = nullptr;
996 request->GetProxyNameByPriority(proxys);
997 LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 end");
998 }
999
1000 HWTEST_F(LocationCommonTest, Request012, TestSize.Level1)
1001 {
1002 GTEST_LOG_(INFO)
1003 << "LocationCommonTest, Request012, TestSize.Level1";
1004 LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 begin");
1005 std::unique_ptr<Request> request = std::make_unique<Request>();
1006 request->requestConfig_ = nullptr;
1007 std::shared_ptr<std::list<std::string>> proxys;
1008 proxys = nullptr;
1009 request->GetProxyNameByPriority(proxys);
1010 LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 end");
1011 }
1012
1013 HWTEST_F(LocationCommonTest, Request013, TestSize.Level1)
1014 {
1015 GTEST_LOG_(INFO)
1016 << "LocationCommonTest, Request013, TestSize.Level1";
1017 LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 begin");
1018 std::unique_ptr<Request> request = std::make_unique<Request>();
1019 request->requestConfig_ = nullptr;
1020 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
1021 request->GetProxyNameByPriority(proxys);
1022 LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 end");
1023 }
1024
1025 HWTEST_F(LocationCommonTest, Request014, TestSize.Level1)
1026 {
1027 GTEST_LOG_(INFO)
1028 << "LocationCommonTest, Request014, TestSize.Level1";
1029 LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 begin");
1030 std::unique_ptr<Request> request = std::make_unique<Request>();
1031 std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
1032 request->requestConfig_->priority_ = PRIORITY_LOW_POWER;
1033 request->GetProxyName(proxys);
1034 request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY;
1035 request->GetProxyName(proxys);
1036 request->requestConfig_->priority_ = LOCATION_PRIORITY_LOCATING_SPEED;
1037 request->GetProxyName(proxys);
1038 request->requestConfig_->priority_ = PRIORITY_ACCURACY;
1039 request->GetProxyName(proxys);
1040 request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX;
1041 request->GetProxyName(proxys);
1042 request->requestConfig_->priority_ = 0;
1043 request->GetProxyName(proxys);
1044 LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 end");
1045 }
1046
1047 HWTEST_F(LocationCommonTest, Request015, TestSize.Level1)
1048 {
1049 GTEST_LOG_(INFO)
1050 << "LocationCommonTest, Request015, TestSize.Level1";
1051 LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 begin");
1052 std::unique_ptr<Request> request = std::make_unique<Request>();
1053 request->GetLocationPermState();
1054 request->GetBackgroundPermState();
1055 bool state = true;
1056 request->SetLocationPermState(state);
1057 request->SetBackgroundPermState(state);
1058 request->SetApproximatelyPermState(state);
1059 sptr<ILocatorCallback> callback;
1060 request->SetLocationErrorCallBack(callback);
1061 LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 end");
1062 }
1063
1064 HWTEST_F(LocationCommonTest, Location001, TestSize.Level1)
1065 {
1066 GTEST_LOG_(INFO)
1067 << "LocationCommonTest, Location001, TestSize.Level1";
1068 LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 begin");
1069 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1070 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1071 location2->latitude_ = MIN_LATITUDE + 1;
1072 location1->LocationEqual(location2);
1073 location2->latitude_ = MIN_LATITUDE - 1;
1074 location2->longitude_ = MIN_LONGITUDE + 1;
1075 location1->LocationEqual(location2);
1076 location2->longitude_ = MIN_LONGITUDE - 1;
1077 location2->altitude_ = 1.0;
1078 location1->LocationEqual(location2);
1079 location2->altitude_ = 0.0;
1080 location2->accuracy_ = 1.0;
1081 location1->LocationEqual(location2);
1082 location2->accuracy_ = 0.0;
1083 location2->speed_ = 1.0;
1084 location1->LocationEqual(location2);
1085 location2->speed_ = 0.0;
1086 location2->direction_ = 1.0;
1087 location1->LocationEqual(location2);
1088 location2->direction_ = 0.0;
1089 location2->timeStamp_ = 1;
1090 location1->LocationEqual(location2);
1091 location2->timeStamp_ = 0;
1092 location2->timeSinceBoot_ = 1;
1093 location1->LocationEqual(location2);
1094 location2->timeSinceBoot_ = 0;
1095 std::vector<std::string> additions;
1096 location2->additions_ = additions;
1097 location2->additionSize_ = 1;
1098 location1->LocationEqual(location2);
1099 location2->additionSize_ = 0;
1100 location2->isFromMock_ = true;
1101 location1->LocationEqual(location2);
1102 location2->isFromMock_ = false;
1103 location1->LocationEqual(location2);
1104 LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 end");
1105 }
1106
1107 HWTEST_F(LocationCommonTest, Location002, TestSize.Level1)
1108 {
1109 GTEST_LOG_(INFO)
1110 << "LocationCommonTest, Location002, TestSize.Level1";
1111 LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 begin");
1112 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1113 std::unique_ptr<Location> location2 = nullptr;
1114 location1->LocationEqual(location2);
1115 LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 end");
1116 }
1117
1118 HWTEST_F(LocationCommonTest, Location003, TestSize.Level1)
1119 {
1120 GTEST_LOG_(INFO)
1121 << "LocationCommonTest, Location003, TestSize.Level1";
1122 LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 begin");
1123 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1124 std::unique_ptr<Location> location2 = nullptr;
1125 location1->AdditionEqual(location2);
1126 LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 end");
1127 }
1128
1129 HWTEST_F(LocationCommonTest, Location004, TestSize.Level1)
1130 {
1131 GTEST_LOG_(INFO)
1132 << "LocationCommonTest, Location004, TestSize.Level1";
1133 LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 begin");
1134 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1135 std::vector<std::string> additions;
1136 location1->additions_ = additions;
1137 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1138 location2->additions_ = additions;
1139 location1->AdditionEqual(location2);
1140 LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 end");
1141 }
1142
1143 HWTEST_F(LocationCommonTest, Location005, TestSize.Level1)
1144 {
1145 GTEST_LOG_(INFO)
1146 << "LocationCommonTest, Location005, TestSize.Level1";
1147 LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 begin");
1148 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1149 std::vector<std::string> additions;
1150 location1->additions_ = additions;
1151 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1152 additions.resize(5);
1153 location2->additions_ = additions;
1154 location1->AdditionEqual(location2);
1155 LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 end");
1156 }
1157
1158 HWTEST_F(LocationCommonTest, Location006, TestSize.Level1)
1159 {
1160 GTEST_LOG_(INFO)
1161 << "LocationCommonTest, Location006, TestSize.Level1";
1162 LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 begin");
1163 std::unique_ptr<Location> location1 = std::make_unique<Location>();
1164 std::vector<std::string> additions1(4, "1");
1165 location1->additions_ = additions1;
1166 std::unique_ptr<Location> location2 = std::make_unique<Location>();
1167 std::vector<std::string> additions2(4, "2");
1168 location2->additions_ = additions2;
1169 location1->AdditionEqual(location2);
1170 LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 end");
1171 }
1172 } // namespace Location
1173 } // namespace OHOS
1174