• 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_impl_test.h"
17 
18 #include "accesstoken_kit.h"
19 #include "message_parcel.h"
20 #include "nativetoken_kit.h"
21 #include "token_setproc.h"
22 
23 #include "cached_locations_callback_host.h"
24 #include "common_utils.h"
25 #include "constant_definition.h"
26 #include "country_code.h"
27 #include "country_code_callback_host.h"
28 #include "geo_address.h"
29 #include "gnss_status_callback_host.h"
30 #include "i_cached_locations_callback.h"
31 #include "location.h"
32 #include "location_switch_callback_host.h"
33 #include "locator_callback_proxy.h"
34 #include "locator_proxy.h"
35 #include "nmea_message_callback_host.h"
36 #include "request_config.h"
37 
38 using namespace testing::ext;
39 
40 namespace OHOS {
41 namespace Location {
42 const int32_t LOCATION_PERM_NUM = 4;
43 const int INVALID_PRIVACY_TYPE = -1;
44 const int INVALID_CACHED_SIZE = 0;
45 const double MOCK_LATITUDE = 99.0;
46 const double MOCK_LONGITUDE = 100.0;
SetUp()47 void LocatorImplTest::SetUp()
48 {
49     MockNativePermission();
50     locatorImpl_ = Locator::GetInstance();
51     ASSERT_TRUE(locatorImpl_ != nullptr);
52     callbackStub_ = new (std::nothrow) LocatorCallbackStub();
53     ASSERT_TRUE(callbackStub_ != nullptr);
54 }
55 
TearDown()56 void LocatorImplTest::TearDown()
57 {
58 }
59 
MockNativePermission()60 void LocatorImplTest::MockNativePermission()
61 {
62     const char *perms[] = {
63         ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(),
64         ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(),
65     };
66     NativeTokenInfoParams infoInstance = {
67         .dcapsNum = 0,
68         .permsNum = LOCATION_PERM_NUM,
69         .aclsNum = 0,
70         .dcaps = nullptr,
71         .perms = perms,
72         .acls = nullptr,
73         .processName = "LocatorImplTest",
74         .aplStr = "system_basic",
75     };
76     tokenId_ = GetAccessTokenId(&infoInstance);
77     SetSelfTokenID(tokenId_);
78     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
79 }
80 
SetGeocodingMockInfo()81 std::vector<std::shared_ptr<GeocodingMockInfo>> LocatorImplTest::SetGeocodingMockInfo()
82 {
83     std::vector<std::shared_ptr<GeocodingMockInfo>> geoMockInfos;
84     std::shared_ptr<GeocodingMockInfo> geocodingMockInfo =
85         std::make_shared<GeocodingMockInfo>();
86     MessageParcel parcel;
87     parcel.WriteString16(Str8ToStr16("locale"));
88     parcel.WriteDouble(MOCK_LATITUDE); // latitude
89     parcel.WriteDouble(MOCK_LONGITUDE); // longitude
90     parcel.WriteInt32(1);
91     parcel.WriteString("localeLanguage");
92     parcel.WriteString("localeCountry");
93     parcel.WriteInt32(1); // size
94     parcel.WriteInt32(0); // line
95     parcel.WriteString("line");
96     parcel.WriteString("placeName");
97     parcel.WriteString("administrativeArea");
98     parcel.WriteString("subAdministrativeArea");
99     parcel.WriteString("locality");
100     parcel.WriteString("subLocality");
101     parcel.WriteString("roadName");
102     parcel.WriteString("subRoadName");
103     parcel.WriteString("premises");
104     parcel.WriteString("postalCode");
105     parcel.WriteString("countryCode");
106     parcel.WriteString("countryName");
107     parcel.WriteInt32(1); // hasLatitude
108     parcel.WriteDouble(MOCK_LATITUDE); // latitude
109     parcel.WriteInt32(1); // hasLongitude
110     parcel.WriteDouble(MOCK_LONGITUDE); // longitude
111     parcel.WriteString("phoneNumber");
112     parcel.WriteString("addressUrl");
113     parcel.WriteBool(true);
114     geocodingMockInfo->ReadFromParcel(parcel);
115     geoMockInfos.emplace_back(std::move(geocodingMockInfo));
116     return geoMockInfos;
117 }
118 
119 HWTEST_F(LocatorImplTest, locatorImplEnableAbilityV9001, TestSize.Level1)
120 {
121     GTEST_LOG_(INFO)
122         << "LocatorImplTest, locatorImplEnableAbilityV9001, TestSize.Level1";
123     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityV9001 begin");
124     auto switchCallbackHost =
125         sptr<LocationSwitchCallbackHost>(new (std::nothrow) LocationSwitchCallbackHost());
126     EXPECT_NE(nullptr, switchCallbackHost);
127     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterSwitchCallbackV9(switchCallbackHost->AsObject()));
128     sleep(1);
129 
130     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->EnableAbilityV9(false));
131     bool isEnabled = false;
132     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->IsLocationEnabledV9(isEnabled));
133 
134     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterSwitchCallbackV9(switchCallbackHost->AsObject()));
135     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityV9001 end");
136 }
137 
138 HWTEST_F(LocatorImplTest, locatorImplEnableAbilityV9002, TestSize.Level1)
139 {
140     GTEST_LOG_(INFO)
141         << "LocatorImplTest, locatorImplEnableAbilityV9002, TestSize.Level1";
142     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityV9002 begin");
143     auto switchCallbackHost =
144         sptr<LocationSwitchCallbackHost>(new (std::nothrow) LocationSwitchCallbackHost());
145     EXPECT_NE(nullptr, switchCallbackHost);
146     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterSwitchCallbackV9(switchCallbackHost->AsObject()));
147     sleep(1);
148 
149     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->EnableAbilityV9(true));
150     bool isEnabled = false;
151     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->IsLocationEnabledV9(isEnabled));
152 
153     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterSwitchCallbackV9(switchCallbackHost->AsObject()));
154     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplEnableAbilityV9002 end");
155 }
156 
157 HWTEST_F(LocatorImplTest, locatorImplGetCachedLocationV9, TestSize.Level1)
158 {
159     GTEST_LOG_(INFO)
160         << "LocatorImplTest, locatorImplGetCachedLocationV9, TestSize.Level1";
161     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetCachedLocationV9 begin");
162 
163     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->EnableLocationMockV9()); // mock switch on
164 
165     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
166     requestConfig->SetPriority(PRIORITY_ACCURACY);
167     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StartLocatingV9(requestConfig, callbackStub_)); // startLocating first
168     sleep(1);
169 
170     int timeInterval = 0;
171     std::vector<std::shared_ptr<Location>> locations;
172     Parcel parcel;
173     parcel.WriteDouble(10.6); // latitude
174     parcel.WriteDouble(10.5); // longitude
175     parcel.WriteDouble(10.4); // altitude
176     parcel.WriteDouble(1.0); // accuracy
177     parcel.WriteDouble(5.0); // speed
178     parcel.WriteDouble(10); // direction
179     parcel.WriteInt64(1611000000); // timestamp
180     parcel.WriteInt64(1611000000); // time since boot
181     parcel.WriteString16(u"additions"); // additions
182     parcel.WriteInt64(1); // additionSize
183     parcel.WriteBool(true); // isFromMock is false
184     parcel.WriteInt32(1); // source type
185     parcel.WriteInt32(0); // floor no.
186     parcel.WriteDouble(1000.0); // floor acc
187     locations.push_back(Location::UnmarshallingShared(parcel));
188     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->SetMockedLocationsV9(timeInterval, locations)); // set fake locations
189     sleep(1);
190 
191     std::unique_ptr<Location> loc = std::make_unique<Location>();
192     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->GetCachedLocationV9(loc)); // get last location
193     ASSERT_TRUE(loc != nullptr);
194     EXPECT_EQ(10.6, loc->GetLatitude());
195     EXPECT_EQ(10.5, loc->GetLongitude());
196 
197     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StopLocatingV9(callbackStub_));
198 
199     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->DisableLocationMockV9());
200     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetCachedLocationV9 end");
201 }
202 
203 HWTEST_F(LocatorImplTest, locatorImplPrivacyStateV9001, TestSize.Level1)
204 {
205     GTEST_LOG_(INFO)
206         << "LocatorImplTest, locatorImplPrivacyStateV9001, TestSize.Level1";
207     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplPrivacyStateV9001 begin");
208     bool isConfirmed = false;
209     EXPECT_EQ(ERRCODE_INVALID_PARAM, locatorImpl_->SetLocationPrivacyConfirmStatusV9(INVALID_PRIVACY_TYPE, true));
210     EXPECT_EQ(ERRCODE_INVALID_PARAM, locatorImpl_->IsLocationPrivacyConfirmedV9(INVALID_PRIVACY_TYPE, isConfirmed));
211     EXPECT_EQ(false, isConfirmed);
212     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplPrivacyStateV9001 end");
213 }
214 
215 HWTEST_F(LocatorImplTest, locatorImplGetCachedGnssLocationsSizeV9, TestSize.Level1)
216 {
217     GTEST_LOG_(INFO)
218         << "LocatorImplTest, locatorImplGetCachedGnssLocationsSizeV9, TestSize.Level1";
219     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetCachedGnssLocationsSizeV9 begin");
220     int size = INVALID_CACHED_SIZE;
221     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->GetCachedGnssLocationsSizeV9(size));
222     EXPECT_EQ(INVALID_CACHED_SIZE, size);
223     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetCachedGnssLocationsSizeV9 end");
224 }
225 
226 HWTEST_F(LocatorImplTest, locatorImplFlushCachedGnssLocationsV9, TestSize.Level1)
227 {
228     GTEST_LOG_(INFO)
229         << "LocatorImplTest, locatorImplFlushCachedGnssLocationsV9, TestSize.Level1";
230     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplFlushCachedGnssLocationsV9 begin");
231     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->FlushCachedGnssLocationsV9());
232     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplFlushCachedGnssLocationsV9 end");
233 }
234 
235 HWTEST_F(LocatorImplTest, locatorImplSendCommandV9, TestSize.Level1)
236 {
237     GTEST_LOG_(INFO)
238         << "LocatorImplTest, locatorImplSendCommandV9, TestSize.Level1";
239     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplSendCommandV9 begin");
240     std::unique_ptr<LocationCommand> command = std::make_unique<LocationCommand>();
241     command->scenario = SCENE_NAVIGATION;
242     command->command = "cmd";
243     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->SendCommandV9(command));
244     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplSendCommandV9 end");
245 }
246 
247 HWTEST_F(LocatorImplTest, locatorImplRequestFenceV9, TestSize.Level1)
248 {
249     GTEST_LOG_(INFO)
250         << "LocatorImplTest, locatorImplRequestFenceV9, TestSize.Level1";
251     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplRequestFenceV9 begin");
252     std::unique_ptr<GeofenceRequest> fenceRequest = std::make_unique<GeofenceRequest>();
253     fenceRequest->scenario = SCENE_NAVIGATION;
254     GeoFence geofence;
255     geofence.latitude = 1.0;
256     geofence.longitude = 2.0;
257     geofence.radius = 3.0;
258     geofence.expiration = 4.0;
259     fenceRequest->geofence = geofence;
260     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->AddFenceV9(fenceRequest));
261     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->RemoveFenceV9(fenceRequest));
262     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplRequestFenceV9 end");
263 }
264 
265 HWTEST_F(LocatorImplTest, locatorImplGetIsoCountryCodeV9, TestSize.Level1)
266 {
267     GTEST_LOG_(INFO)
268         << "LocatorImplTest, locatorImplGetIsoCountryCodeV9, TestSize.Level1";
269     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetIsoCountryCodeV9 begin");
270 
271     auto countryCodeCallbackHost =
272         sptr<CountryCodeCallbackHost>(new (std::nothrow) CountryCodeCallbackHost());
273     EXPECT_NE(nullptr, countryCodeCallbackHost);
274     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterCountryCodeCallbackV9(countryCodeCallbackHost->AsObject()));
275     sleep(1);
276 
277     std::shared_ptr<CountryCode> countryCode = std::make_shared<CountryCode>();
278     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->GetIsoCountryCodeV9(countryCode));
279     ASSERT_TRUE(countryCode != nullptr);
280     LBSLOGI(LOCATOR, "countrycode : %{public}s", countryCode->ToString().c_str());
281     sleep(1);
282     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterCountryCodeCallbackV9(countryCodeCallbackHost->AsObject()));
283     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetIsoCountryCodeV9 end");
284 }
285 
286 HWTEST_F(LocatorImplTest, locatorImplProxyUidForFreezeV9, TestSize.Level1)
287 {
288     GTEST_LOG_(INFO)
289         << "LocatorImplTest, locatorImplProxyUidForFreezeV9, TestSize.Level1";
290     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplProxyUidForFreezeV9 begin");
291     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->ProxyUidForFreezeV9(SYSTEM_UID, true));
292 
293     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->ProxyUidForFreezeV9(SYSTEM_UID, false));
294 
295     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->ResetAllProxyV9());
296     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplProxyUidForFreezeV9 end");
297 }
298 
299 HWTEST_F(LocatorImplTest, locatorImplIsGeoServiceAvailableV9001, TestSize.Level1)
300 {
301     GTEST_LOG_(INFO)
302         << "LocatorImplTest, locatorImplIsGeoServiceAvailableV9001, TestSize.Level1";
303     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplIsGeoServiceAvailableV9001 begin");
304     bool isAvailable = false;
305     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->EnableReverseGeocodingMockV9());
306     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->IsGeoServiceAvailableV9(isAvailable));
307     EXPECT_EQ(true, isAvailable);
308 
309     isAvailable = false;
310     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->DisableReverseGeocodingMockV9());
311     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->IsGeoServiceAvailableV9(isAvailable));
312     EXPECT_EQ(false, isAvailable);
313     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplIsGeoServiceAvailableV9001 end");
314 }
315 
316 HWTEST_F(LocatorImplTest, locatorImplGetAddressByCoordinateV9001, TestSize.Level1)
317 {
318     GTEST_LOG_(INFO)
319         << "LocatorImplTest, locatorImplGetAddressByCoordinateV9001, TestSize.Level1";
320     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetAddressByCoordinateV9001 begin");
321     MessageParcel request001;
322     std::list<std::shared_ptr<GeoAddress>> geoAddressList001;
323     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->EnableReverseGeocodingMockV9());
324 
325     std::vector<std::shared_ptr<GeocodingMockInfo>> mockInfos = SetGeocodingMockInfo();
326     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->SetReverseGeocodingMockInfoV9(mockInfos));
327     request001.WriteInterfaceToken(LocatorProxy::GetDescriptor());
328     request001.WriteDouble(MOCK_LATITUDE); // latitude
329     request001.WriteDouble(MOCK_LONGITUDE); // longitude
330     request001.WriteInt32(3); // maxItems
331     request001.WriteInt32(1); // locale object size = 1
332     request001.WriteString16(Str8ToStr16("Language")); // locale.getLanguage()
333     request001.WriteString16(Str8ToStr16("Country")); // locale.getCountry()
334     request001.WriteString16(Str8ToStr16("Variant")); // locale.getVariant()
335     request001.WriteString16(Str8ToStr16("")); // ""
336     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->GetAddressByCoordinateV9(request001, geoAddressList001));
337     EXPECT_EQ(false, geoAddressList001.empty());
338 
339     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->DisableReverseGeocodingMockV9());
340     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetAddressByCoordinateV9001 end");
341 }
342 
343 HWTEST_F(LocatorImplTest, locatorImplGetAddressByCoordinateV9002, TestSize.Level1)
344 {
345     GTEST_LOG_(INFO)
346         << "LocatorImplTest, locatorImplGetAddressByCoordinateV9002, TestSize.Level1";
347     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetAddressByCoordinateV9002 begin");
348     MessageParcel request002;
349     std::list<std::shared_ptr<GeoAddress>> geoAddressList002;
350     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->DisableReverseGeocodingMockV9());
351 
352     request002.WriteInterfaceToken(LocatorProxy::GetDescriptor());
353     request002.WriteDouble(1.0); // latitude
354     request002.WriteDouble(2.0); // longitude
355     request002.WriteInt32(3); // maxItems
356     request002.WriteInt32(1); // locale object size = 1
357     request002.WriteString16(Str8ToStr16("Language")); // locale.getLanguage()
358     request002.WriteString16(Str8ToStr16("Country")); // locale.getCountry()
359     request002.WriteString16(Str8ToStr16("Variant")); // locale.getVariant()
360     request002.WriteString16(Str8ToStr16("")); // ""
361     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->GetAddressByCoordinateV9(request002, geoAddressList002));
362     EXPECT_EQ(true, geoAddressList002.empty());
363     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetAddressByCoordinateV9002 end");
364 }
365 
366 HWTEST_F(LocatorImplTest, locatorImplGetAddressByLocationNameV9001, TestSize.Level1)
367 {
368     GTEST_LOG_(INFO)
369         << "LocatorImplTest, locatorImplGetAddressByLocationNameV9001, TestSize.Level1";
370     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetAddressByLocationNameV9001 begin");
371     MessageParcel request003;
372     std::list<std::shared_ptr<GeoAddress>> geoAddressList003;
373     request003.WriteInterfaceToken(LocatorProxy::GetDescriptor());
374     request003.WriteString16(Str8ToStr16("description")); // description
375     request003.WriteDouble(1.0); // minLatitude
376     request003.WriteDouble(2.0); // minLongitude
377     request003.WriteDouble(3.0); // maxLatitude
378     request003.WriteDouble(4.0); // maxLongitude
379     request003.WriteInt32(3); // maxItems
380     request003.WriteInt32(1); // locale object size = 1
381     request003.WriteString16(Str8ToStr16("Language")); // locale.getLanguage()
382     request003.WriteString16(Str8ToStr16("Country")); // locale.getCountry()
383     request003.WriteString16(Str8ToStr16("Variant")); // locale.getVariant()
384     request003.WriteString16(Str8ToStr16("")); // ""
385     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->GetAddressByLocationNameV9(request003, geoAddressList003));
386     EXPECT_EQ(true, geoAddressList003.empty());
387     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGetAddressByLocationNameV9001 end");
388 }
389 
390 HWTEST_F(LocatorImplTest, locatorImplRegisterAndUnregisterCallbackV9001, TestSize.Level1)
391 {
392     GTEST_LOG_(INFO)
393         << "LocatorImplTest, locatorImplRegisterAndUnregisterCallbackV9001, TestSize.Level1";
394     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplRegisterAndUnregisterCallbackV9001 begin");
395     auto cachedLocationsCallbackHost =
396         sptr<CachedLocationsCallbackHost>(new (std::nothrow) CachedLocationsCallbackHost());
397     EXPECT_NE(nullptr, cachedLocationsCallbackHost);
398     auto cachedCallback = sptr<ICachedLocationsCallback>(cachedLocationsCallbackHost);
399     EXPECT_NE(nullptr, cachedCallback);
400     auto request = std::make_unique<CachedGnssLocationsRequest>();
401     EXPECT_NE(nullptr, request);
402     request->reportingPeriodSec = 10;
403     request->wakeUpCacheQueueFull = true;
404     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->RegisterCachedLocationCallbackV9(request, cachedCallback));
405     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, locatorImpl_->UnregisterCachedLocationCallbackV9(cachedCallback));
406     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplRegisterAndUnregisterCallbackV9001 end");
407 }
408 
409 HWTEST_F(LocatorImplTest, locatorImplGnssStatusCallbackV9, TestSize.Level1)
410 {
411     GTEST_LOG_(INFO)
412         << "LocatorImplTest, locatorImplGnssStatusCallbackV9, TestSize.Level1";
413     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGnssStatusCallbackV9 begin");
414     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
415     requestConfig->SetPriority(PRIORITY_ACCURACY);
416     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StartLocatingV9(requestConfig, callbackStub_)); // startLocating first
417     sleep(1);
418     auto gnssCallbackHost =
419         sptr<GnssStatusCallbackHost>(new (std::nothrow) GnssStatusCallbackHost());
420     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterGnssStatusCallbackV9(gnssCallbackHost->AsObject()));
421     sleep(1);
422     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterGnssStatusCallbackV9(gnssCallbackHost->AsObject()));
423     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StopLocatingV9(callbackStub_)); // after reg, stop locating
424     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplGnssStatusCallbackV9 end");
425 }
426 
427 HWTEST_F(LocatorImplTest, locatorImplNmeaMessageCallbackV9001, TestSize.Level1)
428 {
429     GTEST_LOG_(INFO)
430         << "LocatorImplTest, locatorImplNmeaMessageCallbackV9001, TestSize.Level1";
431     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplNmeaMessageCallbackV9001 begin");
432     std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
433     requestConfig->SetPriority(PRIORITY_ACCURACY);
434     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StartLocatingV9(requestConfig, callbackStub_)); // startLocating first
435     sleep(1);
436     auto nmeaCallbackHost =
437         sptr<NmeaMessageCallbackHost>(new (std::nothrow) NmeaMessageCallbackHost());
438     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->RegisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject()));
439     sleep(1);
440     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->UnregisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject()));
441     EXPECT_EQ(ERRCODE_SUCCESS, locatorImpl_->StopLocatingV9(callbackStub_)); // after reg, stop locating
442     LBSLOGI(LOCATOR, "[LocatorImplTest] locatorImplNmeaMessageCallbackV9001 end");
443 }
444 
445 
446 }  // namespace Location
447 }  // namespace OHOS