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