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 "locator_service_test.h"
17 
18 #include <cstdlib>
19 
20 #include "accesstoken_kit.h"
21 #include "bundle_mgr_interface.h"
22 #include "bundle_mgr_proxy.h"
23 #include "if_system_ability_manager.h"
24 #include "ipc_skeleton.h"
25 #include "iservice_registry.h"
26 #include "nativetoken_kit.h"
27 #include "system_ability_definition.h"
28 #include "token_setproc.h"
29 
30 #include "app_identity.h"
31 #ifdef FEATURE_GNSS_SUPPORT
32 #include "cached_locations_callback_napi.h"
33 #endif
34 #include "common_utils.h"
35 #include "constant_definition.h"
36 #include "country_code.h"
37 #include "country_code_callback_napi.h"
38 #ifdef FEATURE_GEOCODE_SUPPORT
39 #include "geo_address.h"
40 #endif
41 #ifdef FEATURE_GNSS_SUPPORT
42 #include "gnss_status_callback_napi.h"
43 #endif
44 #include "i_locator.h"
45 #include "location.h"
46 #include "location_log.h"
47 #include "location_sa_load_manager.h"
48 #include "location_switch_callback_napi.h"
49 #include "locator.h"
50 #include "locator_callback_napi.h"
51 #include "locator_callback_proxy.h"
52 #define private public
53 #include "locator_skeleton.h"
54 #undef private
55 #ifdef FEATURE_GNSS_SUPPORT
56 #include "nmea_message_callback_napi.h"
57 #endif
58 #include "permission_manager.h"
59 #include "geofence_request.h"
60 #include "location_data_rdb_manager.h"
61 
62 using namespace testing::ext;
63 
64 namespace OHOS {
65 namespace Location {
66 const int32_t LOCATION_PERM_NUM = 6;
67 #ifdef FEATURE_GEOCODE_SUPPORT
68 const double MOCK_LATITUDE = 99.0;
69 const double MOCK_LONGITUDE = 100.0;
70 #endif
71 const int REQUEST_MAX_NUM = 3;
72 const int UNKNOWN_SERVICE_ID = -1;
73 const int GET_SWITCH_STATE = 1;
74 const int DISABLED_SWITCHMODE = 0;
75 const int ENABLED_SWITCHMODE = 1;
76 const int DEFAULT_SWITCHMODE = 2;
77 const std::string ARGS_HELP = "-h";
78 const std::string RUNNING_STATE_OBSERVER = "ohos.permission.RUNNING_STATE_OBSERVER";
SetUp()79 void LocatorServiceTest::SetUp()
80 {
81     /*
82      * @tc.setup: Get system ability's pointer and get sa proxy object.
83      */
84     LoadSystemAbility();
85     MockNativePermission();
86     sptr<ISystemAbilityManager> systemAbilityManager =
87         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
88     EXPECT_NE(nullptr, systemAbilityManager);
89     sptr<IRemoteObject> object = systemAbilityManager->GetSystemAbility(LOCATION_LOCATOR_SA_ID);
90     EXPECT_NE(nullptr, object);
91     proxy_ = new (std::nothrow) LocatorProxy(object);
92     EXPECT_NE(nullptr, proxy_);
93     callbackStub_ = new (std::nothrow) LocatorCallbackStub();
94     EXPECT_NE(nullptr, callbackStub_);
95     backgroundProxy_ = LocatorBackgroundProxy::GetInstance();
96     EXPECT_NE(nullptr, backgroundProxy_);
97     request_ = std::make_shared<Request>();
98     EXPECT_NE(nullptr, request_);
99     request_->SetLocatorCallBack(callbackStub_);
100     request_->SetUid(SYSTEM_UID);
101     request_->SetPid(getpid());
102     SetStartUpConfirmed(true);
103     ChangedLocationMode(true);
104 }
105 
TearDown()106 void LocatorServiceTest::TearDown()
107 {
108     /*
109      * @tc.teardown: release memory.
110      */
111     proxy_ = nullptr;
112     callbackStub_ = nullptr;
113     backgroundProxy_ = nullptr;
114 }
115 
LoadSystemAbility()116 void LocatorServiceTest::LoadSystemAbility()
117 {
118     LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_LOCATOR_SA_ID);
119 #ifdef FEATURE_GNSS_SUPPORT
120     LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_GNSS_SA_ID);
121 #endif
122 #ifdef FEATURE_PASSIVE_SUPPORT
123     LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_NOPOWER_LOCATING_SA_ID);
124 #endif
125 #ifdef FEATURE_NETWORK_SUPPORT
126     LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_NETWORK_LOCATING_SA_ID);
127 #endif
128 #ifdef FEATURE_GEOCODE_SUPPORT
129     LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_GEO_CONVERT_SA_ID);
130 #endif
131 }
132 
MockNativePermission()133 void LocatorServiceTest::MockNativePermission()
134 {
135     const char *perms[] = {
136         ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(),
137         ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(),
138         RUNNING_STATE_OBSERVER.c_str(), ACCESS_CONTROL_LOCATION_SWITCH.c_str(),
139     };
140     NativeTokenInfoParams infoInstance = {
141         .dcapsNum = 0,
142         .permsNum = LOCATION_PERM_NUM,
143         .aclsNum = 0,
144         .dcaps = nullptr,
145         .perms = perms,
146         .acls = nullptr,
147         .processName = "LocatorTest",
148         .aplStr = "system_basic",
149     };
150     tokenId_ = GetAccessTokenId(&infoInstance);
151     SetSelfTokenID(tokenId_);
152     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
153 }
154 
SetStartUpConfirmed(bool isAuthorized)155 void LocatorServiceTest::SetStartUpConfirmed(bool isAuthorized)
156 {
157     std::string value = isAuthorized ? "1" : "0";
158     std::string executeCmd = "settings put SECURE high_accuracy_startup_comfirm " + value;
159     system(executeCmd.c_str());
160 }
161 
ChangedLocationMode(bool isEnable)162 void LocatorServiceTest::ChangedLocationMode(bool isEnable)
163 {
164     std::string value = isEnable ? "3" : "0";
165     std::string executeCmd = "settings put SECURE location_mode " + value;
166     system(executeCmd.c_str());
167 }
168 
StartAndStopForLocating(MessageParcel & data)169 bool LocatorServiceTest::StartAndStopForLocating(MessageParcel& data)
170 {
171     auto locatorImpl = Locator::GetInstance();
172     std::unique_ptr<RequestConfig> requestConfig = RequestConfig::Unmarshalling(data);
173     locatorImpl->StartLocating(requestConfig, callbackStub_);
174     locatorImpl->StopLocating(callbackStub_);
175     return true;
176 }
177 
178 #ifdef FEATURE_GEOCODE_SUPPORT
SetGeocodingMockInfo()179 std::vector<std::shared_ptr<GeocodingMockInfo>> LocatorServiceTest::SetGeocodingMockInfo()
180 {
181     std::vector<std::shared_ptr<GeocodingMockInfo>> geoMockInfos;
182     std::shared_ptr<GeocodingMockInfo> geocodingMockInfo =
183         std::make_shared<GeocodingMockInfo>();
184     MessageParcel parcel;
185     parcel.WriteString16(Str8ToStr16("locale"));
186     parcel.WriteDouble(MOCK_LATITUDE); // latitude
187     parcel.WriteDouble(MOCK_LONGITUDE); // longitude
188     parcel.WriteInt32(1);
189     parcel.WriteString("localeLanguage");
190     parcel.WriteString("localeCountry");
191     parcel.WriteInt32(1); // size
192     parcel.WriteInt32(0); // line
193     parcel.WriteString("line");
194     parcel.WriteString("placeName");
195     parcel.WriteString("administrativeArea");
196     parcel.WriteString("subAdministrativeArea");
197     parcel.WriteString("locality");
198     parcel.WriteString("subLocality");
199     parcel.WriteString("roadName");
200     parcel.WriteString("subRoadName");
201     parcel.WriteString("premises");
202     parcel.WriteString("postalCode");
203     parcel.WriteString("countryCode");
204     parcel.WriteString("countryName");
205     parcel.WriteInt32(1); // hasLatitude
206     parcel.WriteDouble(MOCK_LATITUDE); // latitude
207     parcel.WriteInt32(1); // hasLongitude
208     parcel.WriteDouble(MOCK_LONGITUDE); // longitude
209     parcel.WriteString("phoneNumber");
210     parcel.WriteString("addressUrl");
211     parcel.WriteBool(true);
212     geocodingMockInfo->ReadFromParcel(parcel);
213     geoMockInfos.emplace_back(std::move(geocodingMockInfo));
214     return geoMockInfos;
215 }
216 #endif
217 
218 /*
219  * @tc.name: CheckSwitchState001
220  * @tc.desc: Check location switch state expect success
221  * @tc.type: FUNC
222  */
223 HWTEST_F(LocatorServiceTest, CheckSwitchState001, TestSize.Level1)
224 {
225     /*
226      * @tc.steps: step1. Call system ability and check switch state whether available.
227      * @tc.expected: step1. get switch state is available.
228      */
229     GTEST_LOG_(INFO)
230         << "LocatorServiceTest, CheckSwitchState001, TestSize.Level1";
231     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckSwitchState001 begin");
232     int result = proxy_->GetSwitchState();
233     EXPECT_EQ(true, (result == ENABLED || result == DISABLED));
234     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckSwitchState001 end");
235 }
236 
237 /*
238  * @tc.name: CheckLocatingForScenario001
239  * @tc.desc: Check start locating based on scenario expect success
240  * @tc.type: FUNC
241  */
242 HWTEST_F(LocatorServiceTest, CheckLocatingForScenario001, TestSize.Level1)
243 {
244     /*
245      * @tc.steps: step1. Call system ability and start locating for SCENE_VEHICLE_NAVIGATION.
246      * @tc.expected: step1. get reply state is successful.
247      */
248     GTEST_LOG_(INFO)
249         << "LocatorServiceTest, CheckLocatingForScenario001, TestSize.Level1";
250     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckLocatingForScenario001 begin");
251     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
252     requestConfig->SetScenario(SCENE_NAVIGATION);
253     MessageParcel data;
254     requestConfig->Marshalling(data);
255     bool ret = StartAndStopForLocating(data);
256     EXPECT_EQ(true, ret);
257     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckLocatingForScenario001 end");
258 }
259 
260 /*
261  * @tc.name: CheckLocatingForConfig001
262  * @tc.desc: Check start locating based on config expect success
263  * @tc.type: FUNC
264  */
265 HWTEST_F(LocatorServiceTest, CheckLocatingForConfig001, TestSize.Level1)
266 {
267     /*
268      * @tc.steps: step1. Call system ability and start locating for HIGHT_ACCURACY/HIGHT_POWER_COST.
269      * @tc.expected: step1. get reply state is successful.
270      */
271     GTEST_LOG_(INFO)
272         << "LocatorServiceTest, CheckLocatingForConfig001, TestSize.Level1";
273     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckLocatingForConfig001 begin");
274     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
275     requestConfig->SetPriority(PRIORITY_ACCURACY);
276     MessageParcel data;
277     requestConfig->Marshalling(data);
278     bool ret = StartAndStopForLocating(data);
279     EXPECT_EQ(true, ret);
280     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckLocatingForConfig001 end");
281 }
282 
283 /*
284  * @tc.name: CheckStopLocating001
285  * @tc.desc: Check stop locating with illegal param and expect fail
286  * @tc.type: FUNC
287  */
288 HWTEST_F(LocatorServiceTest, CheckStopLocating001, TestSize.Level1)
289 {
290     /*
291      * @tc.steps: step1. Call system ability and stop locating whit illegal param.
292      * @tc.expected: step1. get reply state is false.
293      */
294     GTEST_LOG_(INFO)
295         << "LocatorServiceTest, CheckStopLocating001, TestSize.Level1";
296     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckStopLocating001 begin");
297     auto locatorImpl = Locator::GetInstance();
298     ASSERT_TRUE(locatorImpl != nullptr);
299     locatorImpl->StopLocating(callbackStub_);
300     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckStopLocating001 end");
301 }
302 
303 /*
304  * @tc.name: CheckGetCacheLocation001
305  * @tc.desc: Check get cache location and expect success
306  * @tc.type: FUNC
307  */
308 HWTEST_F(LocatorServiceTest, CheckGetCacheLocation001, TestSize.Level1)
309 {
310     /*
311      * @tc.steps: step1. Call system ability and get cache location.
312      * @tc.expected: step1. get reply state is true.
313      */
314     GTEST_LOG_(INFO)
315         << "LocatorServiceTest, CheckGetCacheLocation001, TestSize.Level1";
316     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckGetCacheLocation001 begin");
317     MessageParcel data;
318     MessageParcel reply;
319     bool ret = false;
320     if (proxy_->GetSwitchState() == 1) {
321         proxy_->GetCacheLocation(reply);
322         ret = reply.ReadInt32() == REPLY_CODE_SECURITY_EXCEPTION;
323         EXPECT_EQ(false, ret);
324     } else {
325         proxy_->GetCacheLocation(reply);
326         ret = reply.ReadInt32() == REPLY_CODE_SECURITY_EXCEPTION;
327         EXPECT_EQ(false, ret);
328     }
329     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckGetCacheLocation001 end");
330 }
331 
332 /*
333  * @tc.name: IsCallbackInProxyTest001
334  * @tc.desc: Check if callback is in the proxy callback list
335  * @tc.type: FUNC
336  */
337 HWTEST_F(LocatorServiceTest, IsCallbackInProxyTest001, TestSize.Level1)
338 {
339     /*
340      * @tc.steps: step1. Check if callback is in the proxy callback list
341      * @tc.expected: step1. return false
342      */
343     GTEST_LOG_(INFO)
344         << "LocatorServiceTest, IsCallbackInProxyTest001, TestSize.Level1";
345     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsCallbackInProxyTest001 begin");
346     bool result =  backgroundProxy_->IsCallbackInProxy(callbackStub_);
347     EXPECT_EQ(false, result);
348     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsCallbackInProxyTest001 end");
349 }
350 
351 /*
352  * @tc.name: OnSuspendTest001
353  * @tc.desc: Test the function of the process enter and exit frozen state
354  * @tc.type: FUNC
355  */
356 HWTEST_F(LocatorServiceTest, OnSuspendTest001, TestSize.Level1)
357 {
358     /*
359      * @tc.steps: step1. Call the onsuspend function, the process enter frozen state
360      * @tc.expected: step1. return true, the callback of the process is in the proxy list
361      * @tc.steps: step2. Call the onsuspend function, the process exit frozen state
362      * @tc.expected: step2. return false, the callback of the process is remove from the proxy list
363      */
364     GTEST_LOG_(INFO)
365         << "LocatorServiceTest, OnSuspendTest001, TestSize.Level1";
366     LBSLOGI(LOCATOR, "[LocatorServiceTest] OnSuspendTest001 begin");
367     backgroundProxy_->OnSuspend(request_, 0);
368     bool result = backgroundProxy_->IsCallbackInProxy(callbackStub_);
369     // no location permission
370     EXPECT_EQ(false, result);
371     backgroundProxy_->OnSuspend(request_, 1);
372     result = backgroundProxy_->IsCallbackInProxy(callbackStub_);
373     EXPECT_EQ(false, result);
374     LBSLOGI(LOCATOR, "[LocatorServiceTest] OnSuspendTest001 end");
375 }
376 
377 /*
378  * @tc.name: OnPermissionChanged001
379  * @tc.desc: Test the function onPermissionChanged and OnDeleteRequestRecord
380  * @tc.type: FUNC
381  */
382 HWTEST_F(LocatorServiceTest, OnPermissionChanged001, TestSize.Level1)
383 {
384     /*
385      * @tc.steps: step1. Call the onsuspend function, the process enter frozen state
386      * @tc.steps: step2. Call onPermissionChanged, the process exit frozen state
387      * @tc.expected: step2. return true, the callback of the process is in the proxy list
388      */
389     GTEST_LOG_(INFO)
390         << "LocatorServiceTest, OnPermissionChanged001, TestSize.Level1";
391     LBSLOGI(LOCATOR, "[LocatorServiceTest] OnPermissionChanged001 begin");
392     backgroundProxy_->OnSuspend(request_, 0);
393     bool result = backgroundProxy_->IsCallbackInProxy(callbackStub_);
394     // no location permission
395     EXPECT_EQ(false, result);
396     backgroundProxy_->OnDeleteRequestRecord(request_);
397     result = backgroundProxy_->IsCallbackInProxy(callbackStub_);
398     EXPECT_EQ(false, result);
399     LBSLOGI(LOCATOR, "[LocatorServiceTest] OnPermissionChanged001 end");
400 }
401 
402 /*
403  * @tc.name: OnSaStateChange001
404  * @tc.desc: Test the function OnSaStateChange
405  * @tc.type: FUNC
406  */
407 HWTEST_F(LocatorServiceTest, OnSaStateChange001, TestSize.Level1)
408 {
409    /*
410      * @tc.steps: step1. Call the onsuspend function, the process enter frozen state
411      * @tc.steps: step2. Call OnSaStateChange, disable locator ability
412      * @tc.expected: step2. return true, do not change proxy list
413      * @tc.steps: step3. Call OnSaStateChange, enable locator ability
414      * @tc.expected: step3. return true, do not change proxy list
415      */
416     GTEST_LOG_(INFO)
417         << "LocatorServiceTest, OnSaStateChange001, TestSize.Level1";
418     LBSLOGI(LOCATOR, "[LocatorServiceTest] OnSaStateChange001 begin");
419     backgroundProxy_->OnSuspend(request_, 0);
420     bool result = backgroundProxy_->IsCallbackInProxy(callbackStub_);
421     // no location permission
422     EXPECT_EQ(false, result);
423     backgroundProxy_->OnSaStateChange(false);
424     result = backgroundProxy_->IsCallbackInProxy(callbackStub_);
425     // no location permission
426     EXPECT_EQ(false, result);
427     backgroundProxy_->OnSaStateChange(true);
428     result = backgroundProxy_->IsCallbackInProxy(callbackStub_);
429     // no location permission
430     EXPECT_EQ(false, result);
431     backgroundProxy_->OnDeleteRequestRecord(request_);
432     LBSLOGI(LOCATOR, "[LocatorServiceTest] OnSaStateChange001 end");
433 }
434 
435 /*
436  * @tc.name: UpdateSaAbility001
437  * @tc.desc: Test update sa ability
438  * @tc.type: FUNC
439  */
440 HWTEST_F(LocatorServiceTest, UpdateSaAbility001, TestSize.Level1)
441 {
442     /*
443      * @tc.steps: step1. test update sa ability
444      * @tc.expected: step1. no exception happens
445      */
446     GTEST_LOG_(INFO)
447         << "LocatorServiceTest, UpdateSaAbility001, TestSize.Level1";
448     LBSLOGI(LOCATOR, "[LocatorServiceTest] UpdateSaAbility001 begin");
449     ASSERT_TRUE(proxy_ != nullptr);
450     proxy_->UpdateSaAbility();
451     LBSLOGI(LOCATOR, "[LocatorServiceTest] UpdateSaAbility001 end");
452 }
453 
454 /*
455  * @tc.name: SetEnableAndDisable001
456  * @tc.desc: Test disable and enable system ability
457  * @tc.type: FUNC
458  */
459 HWTEST_F(LocatorServiceTest, SetEnableAndDisable001, TestSize.Level1)
460 {
461     /*
462      * @tc.steps: step1.test the switch enable and disable function
463      * @tc.expected: step1. switch set should be true, or setting will return error.
464      */
465     GTEST_LOG_(INFO)
466         << "LocatorServiceTest, SetEnableAndDisable001, TestSize.Level1";
467     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetEnableAndDisable001 begin");
468     bool ret = false;
469     if (proxy_->GetSwitchState() == 1) {
470         proxy_->EnableAbility(false); // if the state is false
471         ret = proxy_ -> GetSwitchState() == 0 ? true : false;
472         EXPECT_EQ(true, ret);
473         // reset the state
474         proxy_->EnableAbility(true);
475     } else {
476         proxy_->EnableAbility(true); // if the state is false
477         ret = proxy_ -> GetSwitchState() == 1 ? true : false;
478         // reset the state
479         proxy_->EnableAbility(false);
480     }
481     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetEnableAndDisable001 end");
482 }
483 
484 /*
485  * @tc.name: RegisterSwitchCallback001
486  * @tc.desc: Test register switch callback if client is null
487  * @tc.type: FUNC
488  */
489 HWTEST_F(LocatorServiceTest, RegisterSwitchCallback001, TestSize.Level1)
490 {
491     /*
492      * @tc.steps: step1.the client is null.
493      */
494     GTEST_LOG_(INFO)
495         << "LocatorServiceTest, RegisterSwitchCallback001, TestSize.Level1";
496     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterSwitchCallback001 begin");
497     pid_t callinguid = 1;
498     sptr<IRemoteObject> client = nullptr;
499 
500     /*
501      * @tc.steps: step2. test register switch callback
502      * @tc.expected: log exception: "register an invalid switch callback"
503      */
504     ASSERT_TRUE(proxy_ != nullptr);
505     proxy_->RegisterSwitchCallback(client, callinguid);
506     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterSwitchCallback001 end");
507 }
508 
509 /*
510  * @tc.name: RegisterSwitchCallback002
511  * @tc.desc: Test register and unregister switch callback if client is not null
512  * @tc.type: FUNC
513  */
514 HWTEST_F(LocatorServiceTest, RegisterAndUnregisterSwitchCallback001, TestSize.Level1)
515 {
516     /*
517      * @tc.steps: step1. give the calling uid
518      */
519     GTEST_LOG_(INFO)
520         << "LocatorServiceTest, RegisterAndUnregisterSwitchCallback001, TestSize.Level1";
521     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterSwitchCallback001 begin");
522     pid_t callinguid = 1;
523 
524     /*
525      * @tc.steps: step2. test register switch callback
526      * @tc.expected: no exception happens.
527      */
528     ASSERT_TRUE(proxy_ != nullptr);
529     proxy_->RegisterSwitchCallback(callbackStub_->AsObject(), callinguid);
530 
531     /*
532      * @tc.steps: step3. test unregister switch callback
533      * @tc.steps: step4. continue to test unregister switch callback
534      * @tc.expected: no exception happens.
535      */
536     proxy_->UnregisterSwitchCallback(callbackStub_->AsObject()); // the callback has been restored in the map
537 
538     proxy_->UnregisterSwitchCallback(callbackStub_->AsObject()); // the map is empty
539     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterSwitchCallback001 end");
540 }
541 
542 /*
543  * @tc.name: UnregisterSwitchCallback001
544  * @tc.desc: Test unregister switch callback if client is null
545  * @tc.type: FUNC
546  */
547 HWTEST_F(LocatorServiceTest, UnregisterSwitchCallback001, TestSize.Level1)
548 {
549     /*
550      * @tc.steps: step1.the client is null.
551      */
552     GTEST_LOG_(INFO)
553         << "LocatorServiceTest, UnregisterSwitchCallback001, TestSize.Level1";
554     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterSwitchCallback001 begin");
555     sptr<IRemoteObject> client = nullptr;
556 
557     /*
558      * @tc.steps: step2. test unregister switch callback
559      * @tc.expected: log exception: LOCATOR: unregister an invalid switch callback
560      */
561     ASSERT_TRUE(proxy_ != nullptr);
562     proxy_->UnregisterSwitchCallback(client);
563     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterSwitchCallback001 end");
564 }
565 
566 /*
567  * @tc.name: RegisterNmeaMessageCallback001
568  * @tc.desc: Test register nmea message callback if client is null
569  * @tc.type: FUNC
570  */
571 #ifdef FEATURE_GNSS_SUPPORT
572 HWTEST_F(LocatorServiceTest, RegisterNmeaMessageCallback001, TestSize.Level1)
573 {
574     /*
575      * @tc.steps: step1.the client is null.
576      */
577     GTEST_LOG_(INFO)
578         << "LocatorServiceTest, RegisterNmeaMessageCallback001, TestSize.Level1";
579     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterNmeaMessageCallback001 begin");
580     pid_t uid = 1;
581     sptr<IRemoteObject> client = nullptr;
582 
583     /*
584      * @tc.steps: step2. test register nmea message callback
585      * @tc.expected: log info : "register an invalid nmea callback".
586      */
587     ASSERT_TRUE(proxy_ != nullptr);
588     proxy_->RegisterNmeaMessageCallback(client, uid);
589     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterNmeaMessageCallback001 end");
590 }
591 #endif
592 
593 /*
594  * @tc.name: RegisterAndUnregisterNmeaMessageCallback001
595  * @tc.desc: Test register nmea message callback and then unregister twice , the first will unreg success,
596  * and the second will not return error.
597  * @tc.type: FUNC
598  */
599 #ifdef FEATURE_GNSS_SUPPORT
600 HWTEST_F(LocatorServiceTest, RegisterAndUnregisterNmeaMessageCallback001, TestSize.Level1)
601 {
602     /*
603      * @tc.steps: step1.the client is not null.
604      */
605     GTEST_LOG_(INFO)
606         << "LocatorServiceTest, RegisterAndUnregisterNmeaMessageCallback001, TestSize.Level1";
607     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterNmeaMessageCallback001 begin");
608     pid_t uid = 1;
609 
610     /*
611      * @tc.steps: step2. test register nmea message callback
612      * @tc.expected: no exception happens
613      */
614     ASSERT_TRUE(proxy_ != nullptr);
615     proxy_->RegisterNmeaMessageCallback(callbackStub_->AsObject(), uid);
616 
617     /*
618      * @tc.steps: step3. test unregister nmea message callback
619      * @tc.steps: step4. continue to test unregister nmea message callback
620      * @tc.expected: no exception happens.
621      */
622     proxy_->UnregisterNmeaMessageCallback(callbackStub_->AsObject()); // callback in map
623     proxy_->UnregisterNmeaMessageCallback(callbackStub_->AsObject()); // map is empty
624     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterNmeaMessageCallback001 end");
625 }
626 #endif
627 
628 /*
629  * @tc.name: UnregisterNmeaMessageCallback001
630  * @tc.desc: Test unregister nmea message callback if client is null
631  * @tc.type: FUNC
632  */
633 #ifdef FEATURE_GNSS_SUPPORT
634 HWTEST_F(LocatorServiceTest, UnregisterNmeaMessageCallback001, TestSize.Level1)
635 {
636     /*
637      * @tc.steps: step1.the client is null.
638      */
639     GTEST_LOG_(INFO)
640         << "LocatorServiceTest, UnregisterNmeaMessageCallback001, TestSize.Level1";
641     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterNmeaMessageCallback001 begin");
642     sptr<IRemoteObject> client = nullptr;
643 
644     /*
645      * @tc.steps: step2. test unregister nmea message callback
646      * @tc.expected: log info : "unregister an invalid nmea callback".
647      */
648     ASSERT_TRUE(proxy_ != nullptr);
649     proxy_->UnregisterNmeaMessageCallback(client);
650     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterNmeaMessageCallback001 end");
651 }
652 #endif
653 
654 /*
655  * @tc.name: GetAddressByLocationName001
656  * @tc.desc: Test get address by location name
657  * @tc.type: FUNC
658  */
659 #ifdef FEATURE_GEOCODE_SUPPORT
660 HWTEST_F(LocatorServiceTest, GetAddressByLocationName001, TestSize.Level1)
661 {
662     /*
663      * @tc.steps: step1.the client is null.
664      */
665     GTEST_LOG_(INFO)
666         << "LocatorServiceTest, GetAddressByLocationName001, TestSize.Level1";
667     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByLocationName001 begin");
668     MessageParcel data;
669     MessageParcel reply;
670     data.WriteInterfaceToken(LocatorProxy::GetDescriptor());
671     data.WriteString16(Str8ToStr16("")); // description
672     data.WriteDouble(10.0); // minLatitude
673     data.WriteDouble(1.0); // minLongitude
674     data.WriteDouble(10.0); // maxLatitude
675     data.WriteDouble(10.0); // maxLongitude
676     data.WriteInt32(10); // maxItems
677     data.WriteInt32(1); // locale object size = 1
678     data.WriteString16(Str8ToStr16("ZH")); // locale.getLanguage()
679     data.WriteString16(Str8ToStr16("cn")); // locale.getCountry()
680     data.WriteString16(Str8ToStr16("")); // locale.getVariant()
681     data.WriteString16(Str8ToStr16("")); // ""
682 
683     /*
684      * @tc.steps: step2. test get address by location name
685      * @tc.expected: return REPLY_CODE_NO_EXCEPTION.
686      */
687     proxy_->GetAddressByLocationName(data, reply);
688     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByLocationName001 end");
689 }
690 #endif
691 
692 /*
693  * @tc.name: RegisterGnssStatusCallback001
694  * @tc.desc: Test register gnss status callback if client is null
695  * @tc.type: FUNC
696  */
697 #ifdef FEATURE_GNSS_SUPPORT
698 HWTEST_F(LocatorServiceTest, RegisterGnssStatusCallback001, TestSize.Level1)
699 {
700     /*
701      * @tc.steps: step1.the client is null.
702      */
703     GTEST_LOG_(INFO)
704         << "LocatorServiceTest, RegisterGnssStatusCallback001, TestSize.Level1";
705     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterGnssStatusCallback001 begin");
706     pid_t lastCallingUid = 1;
707     sptr<IRemoteObject> client = nullptr;
708 
709     /*
710      * @tc.steps: step2. test register gnss status callback
711      * @tc.expected: log info : "SendRegisterMsgToRemote callback is nullptr".
712      */
713     ASSERT_TRUE(proxy_ != nullptr);
714     proxy_->RegisterGnssStatusCallback(client, lastCallingUid);
715     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterGnssStatusCallback001 end");
716 }
717 #endif
718 
719 /*
720  * @tc.name: RegisterAndUnregisterGnssStatusCallback001
721  * @tc.desc: Test register and unregister gnss status callback if client is not null
722  * @tc.type: FUNC
723  */
724 #ifdef FEATURE_GNSS_SUPPORT
725 HWTEST_F(LocatorServiceTest, RegisterAndUnregisterGnssStatusCallback001, TestSize.Level1)
726 {
727     /*
728      * @tc.steps: step1. give the last calling uid
729      */
730     GTEST_LOG_(INFO)
731         << "LocatorServiceTest, RegisterAndUnregisterGnssStatusCallback001, TestSize.Level1";
732     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterGnssStatusCallback001 begin");
733     pid_t lastCallingUid = 1;
734 
735     /*
736      * @tc.steps: step2. test register gnss status callback
737      * @tc.expected: no exception happens.
738      */
739     ASSERT_TRUE(proxy_ != nullptr);
740     proxy_->RegisterGnssStatusCallback(callbackStub_->AsObject(), lastCallingUid);
741 
742     /*
743      * @tc.steps: step3. test unregister gnss status callback
744      * @tc.steps: step4. continue to test unregister gnss status callback
745      * @tc.expected: no exception happens
746      */
747     proxy_->UnregisterGnssStatusCallback(callbackStub_->AsObject()); // callback in map
748     proxy_->UnregisterGnssStatusCallback(callbackStub_->AsObject()); // map is empty
749     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterGnssStatusCallback001 end");
750 }
751 #endif
752 
753 /*
754  * @tc.name: UnregisterGnssStatusCallback001
755  * @tc.desc: Test unregister gnss status callback if client is null
756  * @tc.type: FUNC
757  */
758 #ifdef FEATURE_GNSS_SUPPORT
759 HWTEST_F(LocatorServiceTest, UnregisterGnssStatusCallback001, TestSize.Level1)
760 {
761     /*
762      * @tc.steps: step1.the client is null.
763      */
764     GTEST_LOG_(INFO)
765         << "LocatorServiceTest, UnregisterGnssStatusCallback001, TestSize.Level1";
766     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterGnssStatusCallback001 begin");
767     sptr<IRemoteObject> client = nullptr;
768 
769     /*
770      * @tc.steps: step2. test unregister gnss status callback
771      * @tc.expected: log info : "unregister an invalid gnssStatus callback".
772      */
773     ASSERT_TRUE(proxy_ != nullptr);
774     proxy_->UnregisterGnssStatusCallback(client);
775     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterGnssStatusCallback001 end");
776 }
777 #endif
778 
779 /*
780  * @tc.name: GetAddressByCoordinate001
781  * @tc.desc: Test get address by coordinate
782  * @tc.type: FUNC
783  */
784 #ifdef FEATURE_GEOCODE_SUPPORT
785 HWTEST_F(LocatorServiceTest, GetAddressByCoordinate001, TestSize.Level1)
786 {
787     /*
788      * @tc.steps: step1. build the data.
789      */
790     GTEST_LOG_(INFO)
791         << "LocatorServiceTest, GetAddressByCoordinate001, TestSize.Level1";
792     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByCoordinate001 begin");
793     MessageParcel reply;
794     MessageParcel data;
795     data.WriteInterfaceToken(LocatorProxy::GetDescriptor());
796     data.WriteDouble(10.5); // latitude
797     data.WriteDouble(30.2); // longitude
798     data.WriteInt32(10); // maxItems
799     data.WriteInt32(1); // locale object size = 1
800     data.WriteString16(Str8ToStr16("ZH")); // locale.getLanguage()
801     data.WriteString16(Str8ToStr16("cn")); // locale.getCountry()
802     data.WriteString16(Str8ToStr16("")); // locale.getVariant()
803     data.WriteString16(Str8ToStr16("")); // ""
804 
805     /*
806      * @tc.steps: step2. test get address by coordinate.
807      * @tc.expected: step2. get reply state is true.
808      */
809     proxy_->GetAddressByCoordinate(data, reply);
810 
811     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByCoordinate001 end");
812 }
813 #endif
814 
815 /*
816  * @tc.name: GetAddressByCoordinate001
817  * @tc.desc: Test get address by coordinate
818  * @tc.type: FUNC
819  */
820 #ifdef FEATURE_GEOCODE_SUPPORT
821 HWTEST_F(LocatorServiceTest, GetAddressByCoordinate002, TestSize.Level1)
822 {
823     /*
824      * @tc.steps: step1. build the data.
825      */
826     GTEST_LOG_(INFO)
827         << "LocatorServiceTest, GetAddressByCoordinate002, TestSize.Level1";
828     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByCoordinate002 begin");
829     MessageParcel reply;
830     MessageParcel data;
831     std::string bundleName = "test";
832     data.WriteInterfaceToken(LocatorProxy::GetDescriptor());
833     data.WriteDouble(10.5); // latitude
834     data.WriteDouble(30.2); // longitude
835     data.WriteInt32(10); // maxItems
836     data.WriteInt32(1); // locale object size = 1
837     data.WriteString16(Str8ToStr16("ZH")); // locale.getLanguage()
838     data.WriteString16(Str8ToStr16("cn")); // locale.getCountry()
839     data.WriteString16(Str8ToStr16("")); // locale.getVariant()
840     data.WriteString16(Str8ToStr16("")); // ""
841     auto locatorAbility = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
842     locatorAbility->GetAddressByCoordinate(data, reply, bundleName);
843     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetAddressByCoordinate002 end");
844 }
845 #endif
846 
847 /*
848  * @tc.name: SetAndCheckLocationPrivacyConfirmStatus001
849  * @tc.desc: Test set and check the status
850  * @tc.type: FUNC
851  */
852 HWTEST_F(LocatorServiceTest, SetAndCheckLocationPrivacyConfirmStatus001, TestSize.Level1)
853 {
854     /*
855      * @tc.steps: step1. set PRIVACY_TYPE_OTHERS type status true.
856      * @tc.steps: step2. set PRIVACY_TYPE_STARTUP type status false.
857      * @tc.steps: step3. set PRIVACY_TYPE_CORE_LOCATION type default.
858      */
859     GTEST_LOG_(INFO)
860         << "LocatorServiceTest, SetAndCheckLocationPrivacyConfirmStatus001, TestSize.Level1";
861     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetAndCheckLocationPrivacyConfirmStatus001 begin");
862     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetLocationPrivacyConfirmStatus(PRIVACY_TYPE_OTHERS, true));
863     proxy_->SetLocationPrivacyConfirmStatus(PRIVACY_TYPE_STARTUP, false);
864 
865     /*
866      * @tc.steps: step4. location privacy confirm should be true when the type is PRIVACY_TYPE_OTHERS.
867      * @tc.steps: step5. location privacy confirm should be false when the type is PRIVACY_TYPE_STARTUP.
868      * @tc.steps: step6. location privacy confirm should be false when the type is PRIVACY_TYPE_CORE_LOCATION.
869      * @tc.steps: step7. location privacy confirm should be false when the type is invalid.
870      * @tc.expected: no exception happens
871      */
872     proxy_->IsLocationPrivacyConfirmed(PRIVACY_TYPE_OTHERS);
873     EXPECT_EQ(false, proxy_->IsLocationPrivacyConfirmed(PRIVACY_TYPE_STARTUP));
874     EXPECT_EQ(false, proxy_->IsLocationPrivacyConfirmed(PRIVACY_TYPE_CORE_LOCATION));
875     EXPECT_EQ(false, proxy_->IsLocationPrivacyConfirmed(-1));
876     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetAndCheckLocationPrivacyConfirmStatus001 end");
877 }
878 
879 /*
880  * @tc.name: RegisterAndUnregisterCachedLocationCallback001
881  * @tc.desc: Test register and unregister cached location callback if the params are not null.
882  * @tc.type: FUNC
883  */
884 #ifdef FEATURE_GNSS_SUPPORT
885 HWTEST_F(LocatorServiceTest, RegisterAndUnregisterCachedLocationCallback001, TestSize.Level1)
886 {
887     /*
888      * @tc.steps: step1. give the calling uid, cached call back, request config
889      */
890     GTEST_LOG_(INFO)
891         << "LocatorServiceTest, RegisterAndUnregisterCachedLocationCallback001, TestSize.Level1";
892     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterCachedLocationCallback001 begin");
893     std::unique_ptr<CachedGnssLocationsRequest> requestConfig = std::make_unique<CachedGnssLocationsRequest>();
894     auto cachedCallbackHost = sptr<CachedLocationsCallbackNapi>(new (std::nothrow) CachedLocationsCallbackNapi());
895     auto cachedCallback = sptr<ICachedLocationsCallback>(cachedCallbackHost);
896     std::string bundleName = "test";
897 
898     /*
899      * @tc.steps: step2. test register cached location callback
900      * @tc.expected: no exception happens.
901      */
902     EXPECT_EQ(REPLY_CODE_NO_EXCEPTION,
903         proxy_->RegisterCachedLocationCallback(requestConfig, cachedCallback, bundleName));
904 
905     /*
906      * @tc.steps: step3. test unregister cached location callback
907      * @tc.steps: step4. continue to test unregister cached location callback
908      * @tc.expected: no exception happens
909      */
910     EXPECT_EQ(REPLY_CODE_NO_EXCEPTION,
911         proxy_->UnregisterCachedLocationCallback(cachedCallback)); // the callback has been restored in the map
912     EXPECT_EQ(REPLY_CODE_NO_EXCEPTION,
913         proxy_->UnregisterCachedLocationCallback(cachedCallback)); // the map is empty
914     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAndUnregisterCachedLocationCallback001 end");
915 }
916 #endif
917 
918 /*
919  * @tc.name: RegisterCachedLocationCallback001
920  * @tc.desc: Test register cached location callback if params are null.
921  * @tc.type: FUNC
922  */
923 #ifdef FEATURE_GNSS_SUPPORT
924 HWTEST_F(LocatorServiceTest, RegisterCachedLocationCallback001, TestSize.Level1)
925 {
926     /*
927      * @tc.steps: step1. give the calling uid, cached call back, request config
928      */
929     GTEST_LOG_(INFO)
930         << "LocatorServiceTest, RegisterCachedLocationCallback001, TestSize.Level1";
931     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterCachedLocationCallback001 begin");
932     std::unique_ptr<CachedGnssLocationsRequest> requestConfig = nullptr;
933     sptr<ICachedLocationsCallback> cachedCallback = nullptr;
934     std::string bundleName = "test";
935 
936     /*
937      * @tc.steps: step2. test register cached location callback
938      * @tc.expected: no exception happens.
939      */
940     EXPECT_EQ(REPLY_CODE_NO_EXCEPTION,
941         proxy_->RegisterCachedLocationCallback(requestConfig, cachedCallback, bundleName));
942     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterCachedLocationCallback001 end");
943 }
944 #endif
945 
946 /*
947  * @tc.name: GetCachedGnssLocationsSize001
948  * @tc.desc: Test get cached gnss location size
949  * @tc.type: FUNC
950  */
951 #ifdef FEATURE_GNSS_SUPPORT
952 HWTEST_F(LocatorServiceTest, GetCachedGnssLocationsSize001, TestSize.Level1)
953 {
954     /*
955      * @tc.steps: step1. test get cached gnss location size.
956      * @tc.expected: step1. get the true size.
957      */
958     GTEST_LOG_(INFO)
959         << "LocatorServiceTest, GetCachedGnssLocationsSize001, TestSize.Level1";
960     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetCachedGnssLocationsSize001 begin");
961     MessageParcel reply;
962     if (proxy_->GetSwitchState() == 1) {
963         EXPECT_EQ(0, proxy_->GetCachedGnssLocationsSize()); // not support now
964     } else {
965         EXPECT_EQ(0, proxy_->GetCachedGnssLocationsSize()); // switch is off
966     }
967     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetCachedGnssLocationsSize001 end");
968 }
969 #endif
970 
971 /*
972  * @tc.name: FlushCachedGnssLocations001
973  * @tc.desc: Test flush cached gnss location
974  * @tc.type: FUNC
975  */
976 #ifdef FEATURE_GNSS_SUPPORT
977 HWTEST_F(LocatorServiceTest, FlushCachedGnssLocations001, TestSize.Level1)
978 {
979     /*
980      * @tc.steps: step1. test flush cached gnss location
981      * @tc.expected: step1. get the true size.
982      */
983     GTEST_LOG_(INFO)
984         << "LocatorServiceTest, FlushCachedGnssLocations001, TestSize.Level1";
985     LBSLOGI(LOCATOR, "[LocatorServiceTest] FlushCachedGnssLocations001 begin");
986     proxy_->FlushCachedGnssLocations();
987     LBSLOGI(LOCATOR, "[LocatorServiceTest] FlushCachedGnssLocations001 end");
988 }
989 #endif
990 
991 /*
992  * @tc.name: SendCommand001
993  * @tc.desc: Test send command
994  * @tc.type: FUNC
995  */
996 #ifdef FEATURE_GNSS_SUPPORT
997 HWTEST_F(LocatorServiceTest, SendCommand001, TestSize.Level1)
998 {
999     /*
1000      * @tc.steps: step1. build location command
1001      */
1002     GTEST_LOG_(INFO)
1003         << "LocatorServiceTest, SendCommand001, TestSize.Level1";
1004     LBSLOGI(LOCATOR, "[LocatorServiceTest] SendCommand001 begin");
1005     MessageParcel data;
1006     std::unique_ptr<LocationCommand> locationCommand = std::make_unique<LocationCommand>();
1007     locationCommand->scenario = data.ReadInt32();
1008     locationCommand->command = data.ReadBool();
1009 
1010     /*
1011      * @tc.steps: step2. test send command.
1012      * @tc.expected: current function is empty, nothing happens
1013      */
1014     ASSERT_TRUE(proxy_ != nullptr);
1015     proxy_->SendCommand(locationCommand);
1016     LBSLOGI(LOCATOR, "[LocatorServiceTest] SendCommand001 end");
1017 }
1018 #endif
1019 
1020 /*
1021  * @tc.name: EnableLocationMock001
1022  * @tc.desc: Test enable location mock in SCENE_CAR_HAILING scenario
1023  * @tc.type: FUNC
1024  */
1025 HWTEST_F(LocatorServiceTest, EnableLocationMock001, TestSize.Level1)
1026 {
1027     /*
1028      * @tc.steps: step1. test enable location mock
1029      * @tc.expected: no exception happens
1030      */
1031     GTEST_LOG_(INFO)
1032         << "LocatorServiceTest, EnableLocationMock001, TestSize.Level1";
1033     LBSLOGI(LOCATOR, "[LocatorServiceTest] EnableLocationMock001 begin");
1034     proxy_->EnableLocationMock();
1035     LBSLOGI(LOCATOR, "[LocatorServiceTest] EnableLocationMock001 end");
1036 }
1037 
1038 /*
1039  * @tc.name: DisableLocationMock001
1040  * @tc.desc: Test disable location mock in SCENE_CAR_HAILING scenario
1041  * @tc.type: FUNC
1042  */
1043 HWTEST_F(LocatorServiceTest, DisableLocationMock001, TestSize.Level1)
1044 {
1045     /*
1046      * @tc.steps: step1. test disable location mock
1047      * @tc.expected: no exception happens
1048      */
1049     GTEST_LOG_(INFO)
1050         << "LocatorServiceTest, DisableLocationMock001, TestSize.Level1";
1051     LBSLOGI(LOCATOR, "[LocatorServiceTest] DisableLocationMock001 begin");
1052     proxy_->DisableLocationMock();
1053     LBSLOGI(LOCATOR, "[LocatorServiceTest] DisableLocationMock001 end");
1054 }
1055 
1056 /*
1057  * @tc.name: SetMockedLocations001
1058  * @tc.desc: Test set location mock in different scenarioes
1059  * @tc.type: FUNC
1060  */
1061 HWTEST_F(LocatorServiceTest, SetMockedLocations001, TestSize.Level1)
1062 {
1063     /*
1064      * @tc.steps: step1. prepare mock info
1065      */
1066     GTEST_LOG_(INFO)
1067         << "LocatorServiceTest, SetMockedLocations001, TestSize.Level1";
1068     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetMockedLocations001 begin");
1069     int timeInterval = 2;
1070     std::vector<std::shared_ptr<Location>> mockLocationArray;
1071     Parcel parcel;
1072     for (int i = 0; i < 2; i++) {
1073         parcel.WriteDouble(10.6); // latitude
1074         parcel.WriteDouble(10.5); // longitude
1075         parcel.WriteDouble(10.4); // altitude
1076         parcel.WriteDouble(1.0); // accuracy
1077         parcel.WriteDouble(5.0); // speed
1078         parcel.WriteDouble(10); // direction
1079         parcel.WriteInt64(1611000000); // timestamp
1080         parcel.WriteInt64(1611000000); // time since boot
1081         parcel.WriteString16(u"additions"); // additions
1082         parcel.WriteInt64(1); // additionSize
1083         parcel.WriteInt32(1); // isFromMock
1084         mockLocationArray.push_back(Location::UnmarshallingShared(parcel));
1085     }
1086 
1087     /*
1088      * @tc.steps: step2. test set mocked locations for different scenarioes
1089      * @tc.expected: no exception happens
1090      */
1091     proxy_->SetMockedLocations(timeInterval, mockLocationArray);
1092     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetMockedLocations001 end");
1093 }
1094 
1095 /*
1096  * @tc.name: EnableReverseGeocodingMock001
1097  * @tc.desc: Test enable reverse geocoding mock
1098  * @tc.type: FUNC
1099  */
1100 #ifdef FEATURE_GEOCODE_SUPPORT
1101 HWTEST_F(LocatorServiceTest, EnableReverseGeocodingMock001, TestSize.Level1)
1102 {
1103     /*
1104      * @tc.steps: step1. test enable reverse geocoding mock
1105      * @tc.expected: no exception happens
1106      */
1107     GTEST_LOG_(INFO)
1108         << "LocatorServiceTest, EnableReverseGeocodingMock001, TestSize.Level1";
1109     LBSLOGI(LOCATOR, "[LocatorServiceTest] EnableReverseGeocodingMock001 begin");
1110     proxy_->EnableReverseGeocodingMock();
1111     LBSLOGI(LOCATOR, "[LocatorServiceTest] EnableReverseGeocodingMock001 end");
1112 }
1113 #endif
1114 
1115 /*
1116  * @tc.name: DisableReverseGeocodingMock001
1117  * @tc.desc: Test disable reverse geocoding mock
1118  * @tc.type: FUNC
1119  */
1120 #ifdef FEATURE_GEOCODE_SUPPORT
1121 HWTEST_F(LocatorServiceTest, DisableReverseGeocodingMock001, TestSize.Level1)
1122 {
1123     /*
1124      * @tc.steps: step1. test disable reverse geocoding mock
1125      * @tc.expected: no exception happens
1126      */
1127     GTEST_LOG_(INFO)
1128         << "LocatorServiceTest, DisableReverseGeocodingMock001, TestSize.Level1";
1129     LBSLOGI(LOCATOR, "[LocatorServiceTest] DisableReverseGeocodingMock001 begin");
1130     proxy_->DisableReverseGeocodingMock();
1131     LBSLOGI(LOCATOR, "[LocatorServiceTest] DisableReverseGeocodingMock001 end");
1132 }
1133 #endif
1134 
1135 /*
1136  * @tc.name: SetReverseGeocodingMockInfo001
1137  * @tc.desc: Test set reverse geocoding mock info
1138  * @tc.type: FUNC
1139  */
1140 #ifdef FEATURE_GEOCODE_SUPPORT
1141 HWTEST_F(LocatorServiceTest, SetReverseGeocodingMockInfo001, TestSize.Level1)
1142 {
1143     /*
1144      * @tc.steps: step1. prepare mock info
1145      */
1146     GTEST_LOG_(INFO)
1147         << "LocatorServiceTest, SetReverseGeocodingMockInfo001, TestSize.Level1";
1148     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetReverseGeocodingMockInfo001 begin");
1149     std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfo;
1150     std::shared_ptr<GeocodingMockInfo> info = std::make_shared<GeocodingMockInfo>();
1151     Parcel data;
1152     data.WriteString16(Str8ToStr16("locale")); // locale
1153     data.WriteDouble(10.5); // latitude
1154     data.WriteDouble(10.6); // longitude
1155     data.WriteInt32(2); // maxItems
1156     info->ReadFromParcel(data);
1157     mockInfo.push_back(info);
1158     /*
1159      * @tc.steps: step2. test set reverse geocoding mock info
1160      * @tc.expected: no exception happens
1161      */
1162     proxy_->SetReverseGeocodingMockInfo(mockInfo);
1163     LBSLOGI(LOCATOR, "[LocatorServiceTest] SetReverseGeocodingMockInfo001 end");
1164 }
1165 #endif
1166 
1167 /*
1168  * @tc.name: CheckPermission001
1169  * @tc.desc: Test the function CheckPermission
1170  * @tc.type: FUNC
1171  * @tc.require: issueI5OSHX
1172  */
1173 HWTEST_F(LocatorServiceTest, CheckPermission001, TestSize.Level1)
1174 {
1175     /*
1176      * @tc.steps: step1. get callingTokenId and callingFirstTokenid.
1177      * @tc.steps: step2. Call GetPermissionLevel and get permission level.
1178      * @tc.expected: step1. get permission level is PERMISSION_ACCURATE.
1179      */
1180     GTEST_LOG_(INFO)
1181         << "LocatorServiceTest, CheckPermission001, TestSize.Level1";
1182     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckPermission001 begin");
1183     uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
1184     uint32_t callingFirstTokenid = IPCSkeleton::GetFirstTokenID();
1185     PermissionManager::GetPermissionLevel(callingTokenId, callingFirstTokenid);
1186     LBSLOGI(LOCATOR, "[LocatorServiceTest] CheckPermission001 end");
1187 }
1188 
1189 /*
1190  * @tc.name: RegisterAppStateObserver001
1191  * @tc.desc: Test the function register app state observer
1192  * @tc.type: FUNC
1193  * @tc.require: issueI5PX7W
1194  */
1195 HWTEST_F(LocatorServiceTest, RegisterAppStateObserver001, TestSize.Level1)
1196 {
1197     /*
1198      * @tc.steps: step1. get the request manager
1199      * @tc.steps: step2. register app state observer
1200      * @tc.expected: return false, permission denied
1201      */
1202     GTEST_LOG_(INFO)
1203         << "LocatorServiceTest, RegisterAppStateObserver001, TestSize.Level1";
1204     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAppStateObserver001 begin");
1205     MockNativePermission();
1206     backgroundProxy_->RegisterAppStateObserver();
1207     LBSLOGI(LOCATOR, "[LocatorServiceTest] RegisterAppStateObserver001 end");
1208 }
1209 
1210 /*
1211  * @tc.name: UnregisterAppStateObserver001
1212  * @tc.desc: Test the function unregister app state observer
1213  * @tc.type: FUNC
1214  * @tc.require: issueI5PX7W
1215  */
1216 HWTEST_F(LocatorServiceTest, UnregisterAppStateObserver001, TestSize.Level1)
1217 {
1218     /*
1219      * @tc.steps: step1. get the request manager
1220      * @tc.steps: step2. unregister app state observer
1221      * @tc.expected: return true, unreg process is success
1222      */
1223     GTEST_LOG_(INFO)
1224         << "LocatorServiceTest, UnregisterAppStateObserver001, TestSize.Level1";
1225     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterAppStateObserver001 begin");
1226     bool ret = backgroundProxy_->UnregisterAppStateObserver();
1227     EXPECT_EQ(true, ret);
1228     LBSLOGI(LOCATOR, "[LocatorServiceTest] UnregisterAppStateObserver001 end");
1229 }
1230 
1231 /*
1232  * @tc.name: UpdateListOnRequestChange001
1233  * @tc.desc: Test update list on request change in normal scenario
1234  * @tc.type: FUNC
1235  * @tc.require: issueI5PX7W
1236  */
1237 HWTEST_F(LocatorServiceTest, UpdateListOnRequestChange001, TestSize.Level1)
1238 {
1239     /*
1240      * @tc.steps: step1. get user id
1241      * @tc.steps: step2. get uid by bundle name and userId
1242      */
1243     GTEST_LOG_(INFO)
1244         << "LocatorServiceTest, UpdateListOnRequestChange001, TestSize.Level1";
1245     LBSLOGI(LOCATOR, "[LocatorServiceTest] UpdateListOnRequestChange001 begin");
1246     int32_t userId = 0;
1247     CommonUtils::GetCurrentUserId(userId);
1248 
1249     sptr<ISystemAbilityManager> smgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1250     EXPECT_NE(nullptr, smgr);
1251     sptr<IRemoteObject> remoteObject = smgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
1252     EXPECT_NE(nullptr, remoteObject);
1253     sptr<AppExecFwk::IBundleMgr> bundleMgrProxy(new AppExecFwk::BundleMgrProxy(remoteObject));
1254     EXPECT_NE(nullptr, bundleMgrProxy);
1255     std::string name = "ohos.global.systemres";
1256     int32_t uid = bundleMgrProxy->GetUidByBundleName(name, userId);
1257 
1258     LBSLOGD(LOCATOR, "bundleName : %{public}s, uid = %{public}d", name.c_str(), uid);
1259 
1260     request_->SetUid(uid);
1261     request_->SetPackageName(name);
1262 
1263     /*
1264      * @tc.steps: step3. test update list on request change function
1265      * @tc.expected: normal scenario covered
1266      */
1267     backgroundProxy_->UpdateListOnRequestChange(request_);
1268     LBSLOGI(LOCATOR, "[LocatorServiceTest] UpdateListOnRequestChange001 end");
1269 }
1270 
1271 /*
1272  * @tc.name: UpdateListOnRequestChange002
1273  * @tc.desc: Test update list on request change in abnormal scenario
1274  * @tc.type: FUNC
1275  * @tc.require: issueI5PX7W
1276  */
1277 HWTEST_F(LocatorServiceTest, UpdateListOnRequestChange002, TestSize.Level1)
1278 {
1279     /*
1280      * @tc.steps: step1. cannot find bundle name if uid is not restored
1281      * @tc.expected: early return because bundleName can not be found
1282      */
1283     GTEST_LOG_(INFO)
1284         << "LocatorServiceTest, UpdateListOnRequestChange002, TestSize.Level1";
1285     LBSLOGI(LOCATOR, "[LocatorServiceTest] UpdateListOnRequestChange002 begin");
1286     ASSERT_TRUE(backgroundProxy_ != nullptr);
1287     backgroundProxy_->UpdateListOnRequestChange(request_);
1288 
1289     /*
1290      * @tc.steps: step2. request is null
1291      * @tc.expected: early return because request is nullptr
1292      */
1293     backgroundProxy_->UpdateListOnRequestChange(nullptr);
1294     LBSLOGI(LOCATOR, "[LocatorServiceTest] UpdateListOnRequestChange002 end");
1295 }
1296 
1297 HWTEST_F(LocatorServiceTest, locatorImpl001, TestSize.Level1)
1298 {
1299     GTEST_LOG_(INFO)
1300         << "LocatorServiceTest, locatorImpl001, TestSize.Level1";
1301     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImpl001 begin");
1302     auto locatorImpl = Locator::GetInstance();
1303     EXPECT_NE(nullptr, locatorImpl);
1304     locatorImpl->ShowNotification();
1305     locatorImpl->RequestPermission();
1306     locatorImpl->RequestEnableLocation();
1307 
1308     locatorImpl->EnableAbility(false);
1309     EXPECT_EQ(false, locatorImpl->IsLocationEnabled());
1310     locatorImpl->EnableAbility(true);
1311 
1312     locatorImpl->GetCachedLocation();
1313 
1314     locatorImpl->SetLocationPrivacyConfirmStatus(1, true);
1315     EXPECT_EQ(true, locatorImpl->IsLocationPrivacyConfirmed(1));
1316     locatorImpl->SetLocationPrivacyConfirmStatus(-1, true);
1317     locatorImpl->IsLocationPrivacyConfirmed(-1);
1318 #ifdef FEATURE_GNSS_SUPPORT
1319     EXPECT_EQ(0, locatorImpl->GetCachedGnssLocationsSize());
1320     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl->FlushCachedGnssLocations());
1321     std::unique_ptr<LocationCommand> command = std::make_unique<LocationCommand>();
1322     command->scenario = SCENE_NAVIGATION;
1323     command->command = "cmd";
1324     EXPECT_EQ(true, locatorImpl->SendCommand(command));
1325 #endif
1326     EXPECT_NE(nullptr, locatorImpl->GetIsoCountryCode());
1327     int timeInterval = 2;
1328     locatorImpl->EnableLocationMock();
1329     std::vector<std::shared_ptr<Location>> locations;
1330     locatorImpl->SetMockedLocations(timeInterval, locations);
1331     locatorImpl->DisableLocationMock();
1332     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImpl001 end");
1333 }
1334 
1335 #ifdef FEATURE_GEOCODE_SUPPORT
1336 HWTEST_F(LocatorServiceTest, locatorImplGeocodingMock001, TestSize.Level1)
1337 {
1338     GTEST_LOG_(INFO)
1339         << "LocatorServiceTest, locatorImplGeocodingMock001, TestSize.Level1";
1340     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGeocodingMock001 begin");
1341     auto locatorImpl = Locator::GetInstance();
1342     EXPECT_NE(nullptr, locatorImpl);
1343     locatorImpl->EnableReverseGeocodingMock();
1344     std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfos = SetGeocodingMockInfo();
1345     locatorImpl->SetReverseGeocodingMockInfo(mockInfos);
1346     locatorImpl->DisableReverseGeocodingMock();
1347     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGeocodingMock001 end");
1348 }
1349 #endif
1350 
1351 #ifdef FEATURE_GEOCODE_SUPPORT
1352 HWTEST_F(LocatorServiceTest, locatorImplGetAddressByCoordinate001, TestSize.Level1)
1353 {
1354     GTEST_LOG_(INFO)
1355         << "LocatorServiceTest, locatorImplGetAddressByCoordinate001, TestSize.Level1";
1356     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGetAddressByCoordinate001 begin");
1357     auto locatorImpl = Locator::GetInstance();
1358     EXPECT_NE(nullptr, locatorImpl);
1359     MessageParcel request001;
1360     std::list<std::shared_ptr<GeoAddress>> geoAddressList001;
1361     locatorImpl->EnableReverseGeocodingMock();
1362 
1363     std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfos = SetGeocodingMockInfo();
1364     locatorImpl->SetReverseGeocodingMockInfo(mockInfos);
1365     request001.WriteInterfaceToken(LocatorProxy::GetDescriptor());
1366     request001.WriteDouble(MOCK_LATITUDE); // latitude
1367     request001.WriteDouble(MOCK_LONGITUDE); // longitude
1368     request001.WriteInt32(3); // maxItems
1369     request001.WriteInt32(1); // locale object size = 1
1370     request001.WriteString16(Str8ToStr16("Language")); // locale.getLanguage()
1371     request001.WriteString16(Str8ToStr16("Country")); // locale.getCountry()
1372     request001.WriteString16(Str8ToStr16("Variant")); // locale.getVariant()
1373     request001.WriteString16(Str8ToStr16("")); // ""
1374     locatorImpl->GetAddressByCoordinate(request001, geoAddressList001);
1375     EXPECT_EQ(true, geoAddressList001.empty());
1376     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGetAddressByCoordinate001 end");
1377 }
1378 #endif
1379 
1380 #ifdef FEATURE_GEOCODE_SUPPORT
1381 HWTEST_F(LocatorServiceTest, locatorImplGetAddressByCoordinate002, TestSize.Level1)
1382 {
1383     GTEST_LOG_(INFO)
1384         << "LocatorServiceTest, locatorImplGetAddressByCoordinate002, TestSize.Level1";
1385     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGetAddressByCoordinate002 begin");
1386     auto locatorImpl = Locator::GetInstance();
1387     EXPECT_NE(nullptr, locatorImpl);
1388     MessageParcel request002;
1389     std::list<std::shared_ptr<GeoAddress>> geoAddressList002;
1390     locatorImpl->DisableReverseGeocodingMock();
1391     request002.WriteInterfaceToken(LocatorProxy::GetDescriptor());
1392     request002.WriteDouble(1.0); // latitude
1393     request002.WriteDouble(2.0); // longitude
1394     request002.WriteInt32(3); // maxItems
1395     request002.WriteInt32(1); // locale object size = 1
1396     request002.WriteString16(Str8ToStr16("Language")); // locale.getLanguage()
1397     request002.WriteString16(Str8ToStr16("Country")); // locale.getCountry()
1398     request002.WriteString16(Str8ToStr16("Variant")); // locale.getVariant()
1399     request002.WriteString16(Str8ToStr16("")); // ""
1400     locatorImpl->GetAddressByCoordinate(request002, geoAddressList002);
1401     EXPECT_EQ(true, geoAddressList002.empty());
1402     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGetAddressByCoordinate002 end");
1403 }
1404 #endif
1405 
1406 #ifdef FEATURE_GEOCODE_SUPPORT
1407 HWTEST_F(LocatorServiceTest, locatorImplGetAddressByLocationName001, TestSize.Level1)
1408 {
1409     GTEST_LOG_(INFO)
1410         << "LocatorServiceTest, locatorImplGetAddressByLocationName001, TestSize.Level1";
1411     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGetAddressByLocationName001 begin");
1412     auto locatorImpl = Locator::GetInstance();
1413     EXPECT_NE(nullptr, locatorImpl);
1414     MessageParcel request003;
1415     std::list<std::shared_ptr<GeoAddress>> geoAddressList003;
1416     request003.WriteInterfaceToken(LocatorProxy::GetDescriptor());
1417     request003.WriteString16(Str8ToStr16("description")); // description
1418     request003.WriteDouble(1.0); // minLatitude
1419     request003.WriteDouble(2.0); // minLongitude
1420     request003.WriteDouble(3.0); // maxLatitude
1421     request003.WriteDouble(4.0); // maxLongitude
1422     request003.WriteInt32(3); // maxItems
1423     request003.WriteInt32(1); // locale object size = 1
1424     request003.WriteString16(Str8ToStr16("Language")); // locale.getLanguage()
1425     request003.WriteString16(Str8ToStr16("Country")); // locale.getCountry()
1426     request003.WriteString16(Str8ToStr16("Variant")); // locale.getVariant()
1427     request003.WriteString16(Str8ToStr16("")); // ""
1428     locatorImpl->GetAddressByLocationName(request003, geoAddressList003);
1429     EXPECT_EQ(true, geoAddressList003.empty());
1430     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplGetAddressByLocationName001 end");
1431 }
1432 #endif
1433 
1434 HWTEST_F(LocatorServiceTest, locatorImplRegisterAndUnregisterCallback001, TestSize.Level1)
1435 {
1436     GTEST_LOG_(INFO)
1437         << "LocatorServiceTest, locatorImplRegisterAndUnregisterCallback001, TestSize.Level1";
1438     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplRegisterAndUnregisterCallback001 begin");
1439     auto locatorImpl = Locator::GetInstance();
1440     EXPECT_NE(nullptr, locatorImpl);
1441     auto switchCallbackHost =
1442         sptr<LocationSwitchCallbackNapi>(new (std::nothrow) LocationSwitchCallbackNapi());
1443     EXPECT_NE(nullptr, switchCallbackHost);
1444     EXPECT_EQ(true, locatorImpl->RegisterSwitchCallback(switchCallbackHost->AsObject(), 1000));
1445     EXPECT_EQ(true, locatorImpl->UnregisterSwitchCallback(switchCallbackHost->AsObject()));
1446 #ifdef FEATURE_GNSS_SUPPORT
1447     auto gnssCallbackHost =
1448         sptr<GnssStatusCallbackNapi>(new (std::nothrow) GnssStatusCallbackNapi());
1449     EXPECT_NE(nullptr, gnssCallbackHost);
1450     EXPECT_EQ(true, locatorImpl->RegisterGnssStatusCallback(gnssCallbackHost->AsObject(), 1000));
1451     EXPECT_EQ(true, locatorImpl->UnregisterGnssStatusCallback(gnssCallbackHost->AsObject()));
1452     auto nmeaCallbackHost =
1453         sptr<NmeaMessageCallbackNapi>(new (std::nothrow) NmeaMessageCallbackNapi());
1454     EXPECT_NE(nullptr, nmeaCallbackHost);
1455     EXPECT_EQ(true, locatorImpl->RegisterNmeaMessageCallback(nmeaCallbackHost->AsObject(), 1000));
1456     EXPECT_EQ(true, locatorImpl->UnregisterNmeaMessageCallback(nmeaCallbackHost->AsObject()));
1457 #endif
1458     auto countryCodeCallbackHost =
1459         sptr<CountryCodeCallbackNapi>(new (std::nothrow) CountryCodeCallbackNapi());
1460     EXPECT_NE(nullptr, countryCodeCallbackHost);
1461     EXPECT_EQ(true, locatorImpl->RegisterCountryCodeCallback(countryCodeCallbackHost->AsObject(), 1000));
1462     EXPECT_EQ(true, locatorImpl->UnregisterCountryCodeCallback(countryCodeCallbackHost->AsObject()));
1463 #ifdef FEATURE_GNSS_SUPPORT
1464     auto cachedLocationsCallbackHost =
1465         sptr<CachedLocationsCallbackNapi>(new (std::nothrow) CachedLocationsCallbackNapi());
1466     EXPECT_NE(nullptr, cachedLocationsCallbackHost);
1467     auto cachedCallback = sptr<ICachedLocationsCallback>(cachedLocationsCallbackHost);
1468     EXPECT_NE(nullptr, cachedCallback);
1469     auto request = std::make_unique<CachedGnssLocationsRequest>();
1470     EXPECT_NE(nullptr, request);
1471     request->reportingPeriodSec = 10;
1472     request->wakeUpCacheQueueFull = true;
1473     locatorImpl->RegisterCachedLocationCallback(request, cachedCallback);
1474     locatorImpl->UnregisterCachedLocationCallback(cachedCallback);
1475 #endif
1476     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorImplRegisterAndUnregisterCallback001 end");
1477 }
1478 
1479 HWTEST_F(LocatorServiceTest, locatorServiceStartAndStop001, TestSize.Level1)
1480 {
1481     auto locatorAbility =
1482         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1483     locatorAbility->OnStart();
1484     EXPECT_EQ(ServiceRunningState::STATE_RUNNING, locatorAbility->QueryServiceState());
1485     locatorAbility->OnStart(); // after state running
1486 
1487     locatorAbility->OnStop();
1488     EXPECT_EQ(ServiceRunningState::STATE_NOT_START, locatorAbility->QueryServiceState());
1489     locatorAbility->locatorHandler_ = nullptr;
1490     locatorAbility->OnStart(); // after stop
1491     EXPECT_EQ(ServiceRunningState::STATE_RUNNING, locatorAbility->QueryServiceState());
1492 }
1493 
1494 HWTEST_F(LocatorServiceTest, locatorServiceStartAndStopSA001, TestSize.Level1)
1495 {
1496     GTEST_LOG_(INFO)
1497         << "LocatorServiceTest, locatorServiceStartAndStopSA001, TestSize.Level1";
1498     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceStartAndStopSA001 begin");
1499     auto locatorAbility =
1500         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1501     locatorAbility->OnAddSystemAbility(UNKNOWN_SERVICE_ID, "device-id");
1502 
1503     locatorAbility->RegisterAction();
1504     EXPECT_EQ(true, locatorAbility->isActionRegistered);
1505     locatorAbility->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "device-id");
1506 
1507     locatorAbility->OnRemoveSystemAbility(UNKNOWN_SERVICE_ID, "device-id");
1508     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceStartAndStopSA001 end");
1509 }
1510 
1511 HWTEST_F(LocatorServiceTest, locatorServiceInitSaAbility001, TestSize.Level1)
1512 {
1513     GTEST_LOG_(INFO)
1514         << "LocatorServiceTest, locatorServiceInitSaAbility001, TestSize.Level1";
1515     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitSaAbility001 begin");
1516     auto locatorAbility =
1517         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1518     ASSERT_TRUE(locatorAbility != nullptr);
1519     locatorAbility->InitSaAbility();
1520     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitSaAbility001 end");
1521 }
1522 
1523 HWTEST_F(LocatorServiceTest, locatorServiceInitRequestManager001, TestSize.Level1)
1524 {
1525     GTEST_LOG_(INFO)
1526         << "LocatorServiceTest, locatorServiceInitRequestManager001, TestSize.Level1";
1527     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitRequestManager001 begin");
1528     auto locatorAbility =
1529         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1530     locatorAbility->InitRequestManagerMap();
1531     EXPECT_EQ(REQUEST_MAX_NUM, locatorAbility->GetRequests()->size());
1532     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitRequestManager001 end");
1533 }
1534 
1535 HWTEST_F(LocatorServiceTest, locatorServiceUpdateSaAbility001, TestSize.Level1)
1536 {
1537     GTEST_LOG_(INFO)
1538         << "LocatorServiceTest, locatorServiceUpdateSaAbility001, TestSize.Level1";
1539     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceUpdateSaAbility001 begin");
1540     auto locatorAbility =
1541         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1542     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->UpdateSaAbility());
1543     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceUpdateSaAbility001 end");
1544 }
1545 
1546 HWTEST_F(LocatorServiceTest, locatorServiceEnableAndDisable001, TestSize.Level1)
1547 {
1548     GTEST_LOG_(INFO)
1549         << "LocatorServiceTest, locatorServiceEnableAndDisable001, TestSize.Level1";
1550     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceEnableAndDisable001 begin");
1551     auto locatorAbility =
1552         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1553     int state = DISABLED;
1554     locatorAbility->EnableAbility(true);
1555 
1556     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state));
1557     locatorAbility->EnableAbility(false);
1558     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state));
1559     locatorAbility->EnableAbility(true);
1560     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state));
1561 
1562     locatorAbility->GetSwitchState(state);
1563 
1564     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceEnableAndDisable001 end");
1565 }
1566 
1567 HWTEST_F(LocatorServiceTest, GetSwitchState001, TestSize.Level1)
1568 {
1569     GTEST_LOG_(INFO)
1570         << "LocatorServiceTest, GetSwitchState001, TestSize.Level1";
1571     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetSwitchState001 begin");
1572     auto locatorAbility = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1573     int state = DISABLED;
1574     LocationDataRdbManager::SetSwitchStateToSysparaForCurrentUser(ENABLED_SWITCHMODE);
1575     locatorAbility->GetSwitchState(state);
1576     LocationDataRdbManager::SetSwitchStateToSysparaForCurrentUser(DISABLED_SWITCHMODE);
1577     locatorAbility->GetSwitchState(state);
1578     LocationDataRdbManager::SetSwitchStateToSysparaForCurrentUser(DEFAULT_SWITCHMODE);
1579     locatorAbility->GetSwitchState(state);
1580     LBSLOGI(LOCATOR, "[LocatorServiceTest] GetSwitchState001 end");
1581 }
1582 
1583 HWTEST_F(LocatorServiceTest, locatorServiceEnableAndDisable002, TestSize.Level1)
1584 {
1585     GTEST_LOG_(INFO)
1586         << "LocatorServiceTest, locatorServiceEnableAndDisable002, TestSize.Level1";
1587     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceEnableAndDisable002 begin");
1588     auto locatorAbility = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1589     int currentSwitchState = LocationDataRdbManager::QuerySwitchState();
1590     bool isEnable = currentSwitchState == 0 ? true: false;
1591     LocationDataRdbManager::SetSwitchStateToDb(0);
1592     locatorAbility->EnableAbility(isEnable);
1593     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceEnableAndDisable002 end");
1594 }
1595 
1596 #ifdef FEATURE_GNSS_SUPPORT
1597 HWTEST_F(LocatorServiceTest, locatorServiceCallbackRegAndUnreg001, TestSize.Level1)
1598 {
1599     GTEST_LOG_(INFO)
1600         << "LocatorServiceTest, locatorServiceCallbackRegAndUnreg001, TestSize.Level1";
1601     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceCallbackRegAndUnreg001 begin");
1602     auto locatorAbility =
1603         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1604     auto cachedLocationsCallbackHost =
1605         sptr<CachedLocationsCallbackNapi>(new (std::nothrow) CachedLocationsCallbackNapi());
1606     auto cachedCallback = sptr<ICachedLocationsCallback>(cachedLocationsCallbackHost);
1607     auto cachedRequest = std::make_unique<CachedGnssLocationsRequest>();
1608     // uid pid not match locationhub process
1609     EXPECT_EQ(ERRCODE_PERMISSION_DENIED,
1610         locatorAbility->RegisterCachedLocationCallback(cachedRequest, cachedCallback, "unit.test"));
1611 
1612     sleep(1);
1613     EXPECT_EQ(ERRCODE_PERMISSION_DENIED,
1614         locatorAbility->UnregisterCachedLocationCallback(cachedCallback)); // uid pid not match locationhub process
1615     sleep(1);
1616     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceCallbackRegAndUnreg001 end");
1617 }
1618 #endif
1619 
1620 HWTEST_F(LocatorServiceTest, locatorServiceSwitchCallback001, TestSize.Level1)
1621 {
1622     GTEST_LOG_(INFO)
1623         << "LocatorServiceTest, locatorServiceSwitchCallback001, TestSize.Level1";
1624     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSwitchCallback001 begin");
1625     auto locatorAbility =
1626         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1627     auto switchCallbackHost =
1628         sptr<LocationSwitchCallbackNapi>(new (std::nothrow) LocationSwitchCallbackNapi());
1629     locatorAbility->OnStart();
1630     EXPECT_EQ(ERRCODE_INVALID_PARAM, locatorAbility->RegisterSwitchCallback(nullptr, SYSTEM_UID));
1631     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->RegisterSwitchCallback(switchCallbackHost, SYSTEM_UID));
1632     EXPECT_EQ(ERRCODE_INVALID_PARAM, locatorAbility->UnregisterSwitchCallback(nullptr));
1633     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->UnregisterSwitchCallback(switchCallbackHost));
1634     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSwitchCallback001 end");
1635 }
1636 
1637 #ifdef FEATURE_GNSS_SUPPORT
1638 HWTEST_F(LocatorServiceTest, locatorServiceGnssStatusCallback001, TestSize.Level1)
1639 {
1640     GTEST_LOG_(INFO)
1641         << "LocatorServiceTest, locatorServiceGnssStatusCallback001, TestSize.Level1";
1642     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGnssStatusCallback001 begin");
1643     auto locatorAbility =
1644         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1645 
1646     auto gnssCallbackHost =
1647         sptr<GnssStatusCallbackNapi>(new (std::nothrow) GnssStatusCallbackNapi());
1648     AppIdentity identity;
1649     identity.SetPid(1);
1650     // uid pid not match locationhub process
1651     EXPECT_EQ(ERRCODE_PERMISSION_DENIED,
1652         locatorAbility->RegisterGnssStatusCallback(nullptr, identity)); // invalid callback
1653     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterGnssStatusCallback(gnssCallbackHost, identity));
1654     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterGnssStatusCallback(nullptr)); // invalid callback
1655     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterGnssStatusCallback(gnssCallbackHost));
1656     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGnssStatusCallback001 end");
1657 }
1658 #endif
1659 
1660 #ifdef FEATURE_GNSS_SUPPORT
1661 HWTEST_F(LocatorServiceTest, locatorServiceNmeaMessageCallback001, TestSize.Level1)
1662 {
1663     GTEST_LOG_(INFO)
1664         << "LocatorServiceTest, locatorServiceNmeaMessageCallback001, TestSize.Level1";
1665     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceNmeaMessageCallback001 begin");
1666     auto locatorAbility =
1667         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1668     auto nmeaCallbackHost =
1669         sptr<NmeaMessageCallbackNapi>(new (std::nothrow) NmeaMessageCallbackNapi());
1670     AppIdentity identity;
1671     identity.SetPid(1);
1672     EXPECT_EQ(ERRCODE_PERMISSION_DENIED,
1673         locatorAbility->RegisterNmeaMessageCallback(nullptr, identity)); // invalid callback
1674     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->RegisterNmeaMessageCallback(nmeaCallbackHost, identity));
1675     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterNmeaMessageCallback(nullptr)); // invalid callback
1676     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->UnregisterNmeaMessageCallback(nmeaCallbackHost));
1677     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceNmeaMessageCallback001 end");
1678 }
1679 #endif
1680 
1681 HWTEST_F(LocatorServiceTest, locatorServicePrivacyConfirmStatus001, TestSize.Level1)
1682 {
1683     GTEST_LOG_(INFO)
1684         << "LocatorServiceTest, locatorServicePrivacyConfirmStatus001, TestSize.Level1";
1685     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePrivacyConfirmStatus001 begin");
1686     auto locatorAbility =
1687         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1688     locatorAbility->SetLocationPrivacyConfirmStatus(PRIVACY_TYPE_STARTUP, true);
1689     bool isConfirmed = false;
1690     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->IsLocationPrivacyConfirmed(PRIVACY_TYPE_STARTUP, isConfirmed));
1691     EXPECT_EQ(true, isConfirmed);
1692     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePrivacyConfirmStatus001 end");
1693 }
1694 
1695 #ifdef FEATURE_GNSS_SUPPORT
1696 HWTEST_F(LocatorServiceTest, locatorServiceSendCommand001, TestSize.Level1)
1697 {
1698     GTEST_LOG_(INFO)
1699         << "LocatorServiceTest, locatorServiceSendCommand001, TestSize.Level1";
1700     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSendCommand001 begin");
1701     auto locatorAbility =
1702         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1703     std::unique_ptr<LocationCommand> command = std::make_unique<LocationCommand>();
1704     command->scenario = SCENE_NAVIGATION;
1705     command->command = "cmd";
1706     // uid pid not match locationhub process
1707     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->SendCommand(command));
1708     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSendCommand001 end");
1709 }
1710 #endif
1711 
1712 HWTEST_F(LocatorServiceTest, locatorServiceLocationMock001, TestSize.Level1)
1713 {
1714     GTEST_LOG_(INFO)
1715         << "LocatorServiceTest, locatorServiceLocationMock001, TestSize.Level1";
1716     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceLocationMock001 begin");
1717     auto locatorAbility =
1718         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1719     int timeInterval = 2;
1720     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->EnableLocationMock());
1721     std::vector<std::shared_ptr<Location>> locations;
1722     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->SetMockedLocations(timeInterval, locations));
1723 
1724     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->DisableLocationMock());
1725     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->SetMockedLocations(timeInterval, locations));
1726     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceLocationMock001 end");
1727 }
1728 
1729 HWTEST_F(LocatorServiceTest, locatorServiceReportLocationStatus001, TestSize.Level1)
1730 {
1731     GTEST_LOG_(INFO)
1732         << "LocatorServiceTest, locatorServiceReportLocationStatus001, TestSize.Level1";
1733     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportLocationStatus001 begin");
1734     auto locatorAbility =
1735         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1736     int state = DISABLED;
1737     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state));
1738     if (state == ENABLED) {
1739         EXPECT_EQ(REPLY_CODE_NO_EXCEPTION, locatorAbility->ReportLocationStatus(callbackStub_, 0));
1740     }
1741     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportLocationStatus001 end");
1742 }
1743 
1744 HWTEST_F(LocatorServiceTest, locatorServiceReportErrorStatus001, TestSize.Level1)
1745 {
1746     GTEST_LOG_(INFO)
1747         << "LocatorServiceTest, locatorServiceReportErrorStatus001, TestSize.Level1";
1748     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportErrorStatus001 begin");
1749     auto locatorAbility =
1750         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1751     int state = DISABLED;
1752     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->GetSwitchState(state));
1753     if (state == ENABLED) {
1754         EXPECT_EQ(REPLY_CODE_NO_EXCEPTION, locatorAbility->ReportErrorStatus(callbackStub_, 0));
1755     }
1756     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportErrorStatus001 end");
1757 }
1758 
1759 HWTEST_F(LocatorServiceTest, locatorServiceGetReceivers001, TestSize.Level1)
1760 {
1761     GTEST_LOG_(INFO)
1762         << "LocatorServiceTest, locatorServiceGetReceivers001, TestSize.Level1";
1763     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGetReceivers001 begin");
1764     auto locatorAbility =
1765         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1766     EXPECT_EQ(0, locatorAbility->GetReceivers()->size());
1767     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGetReceivers001 end");
1768 }
1769 
1770 HWTEST_F(LocatorServiceTest, locatorServiceProxyForFreeze001, TestSize.Level1)
1771 {
1772     GTEST_LOG_(INFO)
1773         << "LocatorServiceTest, locatorServiceProxyForFreeze001, TestSize.Level1";
1774     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceProxyForFreeze001 begin");
1775     auto locatorAbility =
1776         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1777     std::set<int> pidList;
1778     pidList.insert(SYSTEM_UID);
1779     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->ProxyForFreeze(pidList, true));
1780     EXPECT_EQ(true, locatorAbility->IsProxyPid(SYSTEM_UID));
1781     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->ProxyForFreeze(pidList, false));
1782     EXPECT_EQ(false, locatorAbility->IsProxyPid(SYSTEM_UID));
1783     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->ProxyForFreeze(pidList, true));
1784     EXPECT_EQ(true, locatorAbility->IsProxyPid(SYSTEM_UID));
1785     EXPECT_EQ(ERRCODE_SUCCESS, locatorAbility->ResetAllProxy());
1786     EXPECT_EQ(false, locatorAbility->IsProxyPid(SYSTEM_UID));
1787     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceProxyForFreeze001 end");
1788 }
1789 
1790 HWTEST_F(LocatorServiceTest, LocatorAbilityStubDump001, TestSize.Level1)
1791 {
1792     GTEST_LOG_(INFO)
1793         << "LocatorServiceTest, LocatorAbilityStubDump001, TestSize.Level1";
1794     LBSLOGI(LOCATOR, "[LocatorServiceTest] LocatorAbilityStubDump001 begin");
1795     auto locatorAbility = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1796     int32_t fd = 0;
1797     std::vector<std::u16string> args;
1798     std::u16string arg1 = Str8ToStr16("arg1");
1799     args.emplace_back(arg1);
1800     std::u16string arg2 = Str8ToStr16("arg2");
1801     args.emplace_back(arg2);
1802     std::u16string arg3 = Str8ToStr16("arg3");
1803     args.emplace_back(arg3);
1804     std::u16string arg4 = Str8ToStr16("arg4");
1805     args.emplace_back(arg4);
1806     EXPECT_EQ(ERR_OK, locatorAbility->Dump(fd, args));
1807 
1808     std::vector<std::u16string> emptyArgs;
1809     EXPECT_EQ(ERR_OK, locatorAbility->Dump(fd, emptyArgs));
1810 
1811     std::vector<std::u16string> helpArgs;
1812     std::u16string helpArg1 = Str8ToStr16(ARGS_HELP);
1813     helpArgs.emplace_back(helpArg1);
1814     EXPECT_EQ(ERR_OK, locatorAbility->Dump(fd, helpArgs));
1815     LBSLOGI(LOCATOR, "[LocatorServiceTest] LocatorAbilityStubDump001 end");
1816 }
1817 
1818 HWTEST_F(LocatorServiceTest, LocatorAbilityGetProxyMap001, TestSize.Level1)
1819 {
1820     GTEST_LOG_(INFO)
1821         << "LocatorServiceTest, LocatorAbilityGetProxyMap001, TestSize.Level1";
1822     LBSLOGI(LOCATOR, "[LocatorServiceTest] LocatorAbilityGetProxyMap001 begin");
1823     auto locatorAbility = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1824     ASSERT_TRUE(locatorAbility != nullptr);
1825     locatorAbility->GetProxyMap();
1826     LBSLOGI(LOCATOR, "[LocatorServiceTest] LocatorAbilityGetProxyMap001 end");
1827 }
1828 
1829 HWTEST_F(LocatorServiceTest, LocatorAbilityGetProxyMap002, TestSize.Level1)
1830 {
1831     GTEST_LOG_(INFO)
1832         << "LocatorServiceTest, LocatorAbilityGetProxyMap002, TestSize.Level1";
1833     LBSLOGI(LOCATOR, "[LocatorServiceTest] LocatorAbilityGetProxyMap002 begin");
1834     auto locatorAbility = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1835     ASSERT_TRUE(locatorAbility != nullptr);
1836     locatorAbility->InitRequestManagerMap();
1837     LBSLOGI(LOCATOR, "[LocatorServiceTest] LocatorAbilityGetProxyMap002 end");
1838 }
1839 
1840 HWTEST_F(LocatorServiceTest, locatorServicePreProxyForFreeze001, TestSize.Level1)
1841 {
1842     GTEST_LOG_(INFO)
1843         << "LocatorServiceTest, locatorServicePreProxyForFreeze001, TestSize.Level1";
1844     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePreProxyForFreeze001 begin");
1845     auto locatorAbility =
1846         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1847     AppIdentity identity;
1848     MessageParcel data;
1849     MessageParcel reply;
1850     identity.SetUid(100);
1851     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->PreProxyForFreeze(data, reply, identity));
1852     EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorAbility->PreResetAllProxy(data, reply, identity));
1853     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePreProxyForFreeze001 end");
1854 }
1855 
1856 HWTEST_F(LocatorServiceTest, locatorServiceOnAddSystemAbility001, TestSize.Level1)
1857 {
1858     GTEST_LOG_(INFO)
1859         << "LocatorServiceTest, locatorServiceOnAddSystemAbility001, TestSize.Level1";
1860     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceOnAddSystemAbility001 begin");
1861     auto locatorAbility =
1862         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1863     locatorAbility->locatorEventSubscriber_ = nullptr;
1864     locatorAbility->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "device-id");
1865     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceOnAddSystemAbility001 end");
1866 }
1867 
1868 HWTEST_F(LocatorServiceTest, locatorServiceOnRemoveSystemAbility001, TestSize.Level1)
1869 {
1870     GTEST_LOG_(INFO)
1871         << "LocatorServiceTest, locatorServiceOnRemoveSystemAbility001, TestSize.Level1";
1872     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceOnRemoveSystemAbility001 begin");
1873     auto locatorAbility =
1874         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1875     locatorAbility->locatorEventSubscriber_ = nullptr;
1876     locatorAbility->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "device-id");
1877 
1878     OHOS::EventFwk::MatchingSkills matchingSkills;
1879     matchingSkills.AddEvent(MODE_CHANGED_EVENT);
1880     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
1881     locatorAbility->locatorEventSubscriber_ = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
1882     locatorAbility->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "device-id");
1883     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceOnRemoveSystemAbility001 end");
1884 }
1885 
1886 HWTEST_F(LocatorServiceTest, locatorServiceOnRemoveSystemAbility002, TestSize.Level1)
1887 {
1888     GTEST_LOG_(INFO)
1889         << "LocatorServiceTest, locatorServiceOnRemoveSystemAbility002, TestSize.Level1";
1890     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceOnRemoveSystemAbility002 begin");
1891     auto locatorAbility =
1892         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1893     locatorAbility->locationPrivacyEventSubscriber_ = nullptr;
1894     locatorAbility->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "device-id");
1895     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceOnRemoveSystemAbility002 end");
1896 }
1897 
1898 HWTEST_F(LocatorServiceTest, locatorServiceInit001, TestSize.Level1)
1899 {
1900     GTEST_LOG_(INFO)
1901         << "LocatorServiceTest, locatorServiceInit001, TestSize.Level1";
1902     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInit001 begin");
1903     auto locatorAbility =
1904         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1905     locatorAbility->registerToAbility_ = true;
1906     locatorAbility->Init();
1907     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInit001 end");
1908 }
1909 
1910 HWTEST_F(LocatorServiceTest, locatorServiceInitRequestManagerMap001, TestSize.Level1)
1911 {
1912     GTEST_LOG_(INFO)
1913         << "LocatorServiceTest, locatorServiceInitRequestManagerMap001, TestSize.Level1";
1914     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitRequestManagerMap001 begin");
1915     auto locatorAbility =
1916         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1917     locatorAbility->requests_ = nullptr;
1918     locatorAbility->InitRequestManagerMap();
1919     locatorAbility->requests_ = std::make_shared<std::map<std::string, std::list<std::shared_ptr<Request>>>>();
1920     locatorAbility->GetActiveRequestNum();
1921     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitRequestManagerMap001 end");
1922 }
1923 
1924 HWTEST_F(LocatorServiceTest, locatorServiceInitSaAbility002, TestSize.Level1)
1925 {
1926     GTEST_LOG_(INFO)
1927         << "LocatorServiceTest, locatorServiceInitSaAbility002, TestSize.Level1";
1928     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitSaAbility002 begin");
1929     auto locatorAbility =
1930         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1931     locatorAbility->proxyMap_ = nullptr;
1932     locatorAbility->InitSaAbility();
1933 
1934     locatorAbility->proxyMap_ = std::make_shared<std::map<std::string, sptr<IRemoteObject>>>();
1935     locatorAbility->InitSaAbility();
1936     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitSaAbility002 end");
1937 }
1938 
1939 HWTEST_F(LocatorServiceTest, locatorServiceSendLocationMockMsgToGnssSa001, TestSize.Level1)
1940 {
1941     GTEST_LOG_(INFO)
1942         << "LocatorServiceTest, locatorServiceSendLocationMockMsgToGnssSa001, TestSize.Level1";
1943     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSendLocationMockMsgToGnssSa001 begin");
1944     auto locatorAbility =
1945         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1946     std::vector<std::shared_ptr<OHOS::Location::Location>> locations;
1947 #ifdef FEATURE_GNSS_SUPPORT
1948     locatorAbility->SendLocationMockMsgToGnssSa(nullptr, 0, locations, 0);
1949 #endif
1950     locatorAbility->SendLocationMockMsgToNetworkSa(nullptr, 0, locations, 0);
1951     locatorAbility->SendLocationMockMsgToPassiveSa(nullptr, 0, locations, 0);
1952     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSendLocationMockMsgToGnssSa001 end");
1953 }
1954 
1955 HWTEST_F(LocatorServiceTest, locatorServiceStartLocating001, TestSize.Level1)
1956 {
1957     GTEST_LOG_(INFO)
1958         << "LocatorServiceTest, locatorServiceStartLocating001, TestSize.Level1";
1959     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceStartLocating001 begin");
1960     auto locatorAbility =
1961         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
1962 
1963     locatorAbility->proxyMap_ = std::make_shared<std::map<std::string, sptr<IRemoteObject>>>();
1964     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
1965     requestConfig->SetFixNumber(1);
1966     requestConfig->SetPriority(LOCATION_PRIORITY_LOCATING_SPEED);
1967     sptr<ILocatorCallback> callbackStub = new (std::nothrow) LocatorCallbackStub();
1968     AppIdentity identity;
1969     MessageParcel parcel;
1970     parcel.WriteDouble(12.0); // latitude
1971     parcel.WriteDouble(13.0); // longitude
1972     parcel.WriteDouble(14.0); // altitude
1973     parcel.WriteDouble(1000.0); // accuracy
1974     parcel.WriteDouble(10.0); // speed
1975     parcel.WriteDouble(90.0); // direction
1976     parcel.WriteInt64(1000000000); // timeStamp
1977     parcel.WriteInt64(1000000000); // timeSinceBoot
1978     parcel.WriteString16(u"additions"); // additions
1979     parcel.WriteInt64(1); // additionSize
1980     parcel.WriteInt32(1); // isFromMock
1981     std::unique_ptr<Location> location = std::make_unique<Location>();
1982     location->ReadFromParcel(parcel);
1983     location->SetLocationSourceType(1);
1984     locatorAbility->reportManager_->UpdateCacheLocation(location, NETWORK_ABILITY);
1985 
1986     LocationDataRdbManager::SetSwitchStateToDb(ENABLED);
1987     locatorAbility->StartLocating(requestConfig, callbackStub, identity);
1988     LocationDataRdbManager::SetSwitchStateToDb(DISABLED);
1989     locatorAbility->StartLocating(requestConfig, callbackStub, identity);
1990 
1991     sptr<IRemoteObject> objectGnss = CommonUtils::GetRemoteObject(LOCATION_GNSS_SA_ID, CommonUtils::InitDeviceId());
1992     locatorAbility->proxyMap_->insert(make_pair(GNSS_ABILITY, objectGnss));
1993     locatorAbility->reportManager_ = nullptr;
1994     locatorAbility->StartLocating(requestConfig, callbackStub, identity);
1995     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceStartLocating001 end");
1996 }
1997 
1998 HWTEST_F(LocatorServiceTest, locatorServiceGetCacheLocation001, TestSize.Level1)
1999 {
2000     GTEST_LOG_(INFO)
2001         << "LocatorServiceTest, locatorServiceGetCacheLocation001, TestSize.Level1";
2002     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGetCacheLocation001 begin");
2003     auto locatorAbility =
2004         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2005     AppIdentity identity;
2006     MessageParcel parcel;
2007     parcel.WriteDouble(0.0);         // latitude
2008     parcel.WriteDouble(0.0);         // longitude
2009     parcel.WriteDouble(14.0);         // altitude
2010     parcel.WriteDouble(1000.0);       // accuracy
2011     parcel.WriteDouble(10.0);         // speed
2012     parcel.WriteDouble(90.0);         // direction
2013     parcel.WriteInt64(1000000000);    // timeStamp
2014     parcel.WriteInt64(1000000000);    // timeSinceBoot
2015     parcel.WriteString16(u"additions"); // additions
2016     parcel.WriteInt64(1);             // additionSize
2017     parcel.WriteInt32(1);          // isFromMock
2018     std::unique_ptr<Location> location = std::make_unique<Location>();
2019     location->ReadFromParcel(parcel);
2020     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceGetCacheLocation001 end");
2021 }
2022 
2023 HWTEST_F(LocatorServiceTest, locatorServiceReportLocation001, TestSize.Level1)
2024 {
2025     GTEST_LOG_(INFO)
2026         << "LocatorServiceTest, locatorServiceReportLocation001, TestSize.Level1";
2027     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportLocation001 begin");
2028     auto locatorAbility =
2029         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2030     AppIdentity identity;
2031     identity.SetPid(1);
2032     identity.SetUid(2);
2033     uint32_t tokenId = static_cast<uint32_t>(tokenId_);
2034     identity.SetTokenId(tokenId);
2035     identity.SetFirstTokenId(0);
2036     identity.SetBundleName("bundleName");
2037     locatorAbility->requests_ = nullptr;
2038     std::unique_ptr<Location> location = std::make_unique<Location>();
2039     EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, locatorAbility->ReportLocation(location, "test", identity));
2040     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportLocation001 end");
2041 }
2042 
2043 HWTEST_F(LocatorServiceTest, locatorServiceRegisterPermissionCallback001, TestSize.Level1)
2044 {
2045     GTEST_LOG_(INFO)
2046         << "LocatorServiceTest, locatorServiceReportLocation001, TestSize.Level1";
2047     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportLocation001 begin");
2048     auto locatorAbility =
2049         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2050 
2051     locatorAbility->permissionMap_ = nullptr;
2052     std::vector<std::string> permissionNameList;
2053     locatorAbility->RegisterPermissionCallback(0, permissionNameList);
2054     locatorAbility->UnregisterPermissionCallback(0);
2055     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceReportLocation001 end");
2056 }
2057 
2058 HWTEST_F(LocatorServiceTest, locatorServiceRemoveUnloadTask001, TestSize.Level1)
2059 {
2060     GTEST_LOG_(INFO)
2061         << "LocatorServiceTest, locatorServiceRemoveUnloadTask001, TestSize.Level1";
2062     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceRemoveUnloadTask001 begin");
2063     auto locatorAbility =
2064         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2065     locatorAbility->RemoveUnloadTask(DEFAULT_CODE);
2066     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceRemoveUnloadTask001 end");
2067 }
2068 
2069 HWTEST_F(LocatorServiceTest, locatorServiceRemoveUnloadTask002, TestSize.Level1)
2070 {
2071     GTEST_LOG_(INFO)
2072         << "LocatorServiceTest, locatorServiceRemoveUnloadTask002, TestSize.Level1";
2073     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceRemoveUnloadTask002 begin");
2074     auto locatorAbility =
2075         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2076     locatorAbility->RemoveUnloadTask(GET_SWITCH_STATE);
2077     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceRemoveUnloadTask002 end");
2078 }
2079 
2080 HWTEST_F(LocatorServiceTest, locatorServicePostUnloadTask001, TestSize.Level1)
2081 {
2082     GTEST_LOG_(INFO)
2083         << "LocatorServiceTest, locatorServicePostUnloadTask001, TestSize.Level1";
2084     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePostUnloadTask001 begin");
2085     auto locatorAbility =
2086         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2087     locatorAbility->PostUnloadTask(static_cast<uint16_t>(LocatorInterfaceCode::PROXY_PID_FOR_FREEZE));
2088     locatorAbility->PostUnloadTask(static_cast<uint16_t>(LocatorInterfaceCode::RESET_ALL_PROXY));
2089     locatorAbility->PostUnloadTask(DEFAULT_CODE);
2090     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePostUnloadTask001 end");
2091 }
2092 
2093 HWTEST_F(LocatorServiceTest, locatorServicePostUnloadTask002, TestSize.Level1)
2094 {
2095     GTEST_LOG_(INFO)
2096         << "LocatorServiceTest, locatorServicePostUnloadTask002, TestSize.Level1";
2097     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePostUnloadTask002 begin");
2098     auto locatorAbility =
2099         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2100     locatorAbility->PostUnloadTask(GET_SWITCH_STATE);
2101     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServicePostUnloadTask002 end");
2102 }
2103 
2104 HWTEST_F(LocatorServiceTest, locatorServiceSendSwitchState001, TestSize.Level1)
2105 {
2106     GTEST_LOG_(INFO)
2107         << "LocatorServiceTest, locatorServiceSendSwitchState001, TestSize.Level1";
2108     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSendSwitchState001 begin");
2109     auto locatorAbility =
2110         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2111     locatorAbility->SendSwitchState(0);
2112     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceSendSwitchState001 end");
2113 }
2114 
2115 HWTEST_F(LocatorServiceTest, locatorServiceInitRequest001, TestSize.Level1)
2116 {
2117     GTEST_LOG_(INFO)
2118         << "LocatorServiceTest, locatorServiceInitRequest001, TestSize.Level1";
2119     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitRequest001 begin");
2120     auto locatorAbility =
2121         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2122     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
2123     AppIdentity identity;
2124     std::shared_ptr<Request> request = std::make_shared<Request>(requestConfig, callbackStub_, identity);
2125     EXPECT_NE(nullptr, request);
2126     LBSLOGI(LOCATOR, "[LocatorServiceTest] locatorServiceInitRequest001 end");
2127 }
2128 
2129 HWTEST_F(LocatorServiceTest, IsCacheVaildScenario001, TestSize.Level1)
2130 {
2131     GTEST_LOG_(INFO)
2132         << "LocatorServiceTest, IsCacheVaildScenario001, TestSize.Level1";
2133     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsCacheVaildScenario001 begin");
2134     auto locatorAbility =
2135         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2136     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
2137     AppIdentity identity;
2138     std::shared_ptr<Request> request = std::make_shared<Request>(requestConfig, callbackStub_, identity);
2139     locatorAbility->IsCacheVaildScenario(request->GetRequestConfig());
2140     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsCacheVaildScenario001 end");
2141 }
2142 
2143 HWTEST_F(LocatorServiceTest, IsSingleRequest001, TestSize.Level1)
2144 {
2145     GTEST_LOG_(INFO)
2146         << "LocatorServiceTest, IsSingleRequest001, TestSize.Level1";
2147     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsSingleRequest001 begin");
2148     auto locatorAbility =
2149         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2150     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
2151     AppIdentity identity;
2152     std::shared_ptr<Request> request = std::make_shared<Request>(requestConfig, callbackStub_, identity);
2153     bool res = locatorAbility->IsSingleRequest(request->GetRequestConfig());
2154     EXPECT_EQ(false, res);
2155     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsSingleRequest001 end");
2156 }
2157 
2158 HWTEST_F(LocatorServiceTest, RemoveInvalidRequests, TestSize.Level1)
2159 {
2160     GTEST_LOG_(INFO)
2161         << "LocatorServiceTest, RemoveInvalidRequests, TestSize.Level1";
2162     LBSLOGI(LOCATOR, "[LocatorServiceTest] RemoveInvalidRequests begin");
2163     auto locatorAbility =
2164         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2165     auto ret = locatorAbility->RemoveInvalidRequests();
2166     EXPECT_EQ(ERRCODE_SUCCESS, ret);
2167     LBSLOGI(LOCATOR, "[LocatorServiceTest] RemoveInvalidRequests end");
2168 }
2169 
2170 HWTEST_F(LocatorServiceTest, IsInvalidRequest, TestSize.Level1)
2171 {
2172     GTEST_LOG_(INFO)
2173         << "LocatorServiceTest, IsInvalidRequest, TestSize.Level1";
2174     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsInvalidRequest begin");
2175     auto locatorAbility =
2176         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2177     std::shared_ptr<Request> request = std::make_shared<Request>();
2178     locatorAbility->IsInvalidRequest(request);
2179     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsInvalidRequest end");
2180 }
2181 
2182 HWTEST_F(LocatorServiceTest, IsPorcessRunning, TestSize.Level1)
2183 {
2184     GTEST_LOG_(INFO)
2185         << "LocatorServiceTest, IsPorcessRunning, TestSize.Level1";
2186     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsPorcessRunning begin");
2187     auto locatorAbility =
2188         sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
2189     auto result = locatorAbility->IsProcessRunning(1000, 1000);
2190     EXPECT_EQ(false, result);
2191     LBSLOGI(LOCATOR, "[LocatorServiceTest] IsPorcessRunning end");
2192 }
2193 }  // namespace Location
2194 }  // namespace OHOS
2195