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