• 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 #ifdef FEATURE_GNSS_SUPPORT
17 #include "gnss_ability_test.h"
18 
19 #include <cstdlib>
20 
21 #include "accesstoken_kit.h"
22 #include "cell_information.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 "common_utils.h"
31 #include "constant_definition.h"
32 #include "gnss_event_callback.h"
33 #include "location_dumper.h"
34 
35 #include "mock_i_cellular_data_manager.h"
36 
37 using namespace testing;
38 using namespace testing::ext;
39 
40 namespace OHOS {
41 namespace Location {
42 using HDI::Location::Agnss::V1_0::IAGnssCallback;
43 using HDI::Location::Agnss::V1_0::AGnssRefInfo;
44 using HDI::Location::Gnss::V1_0::IGnssCallback;
45 using HDI::Location::Gnss::V1_0::LocationInfo;
46 const int32_t LOCATION_PERM_NUM = 4;
47 const std::string ARGS_HELP = "-h";
SetUp()48 void GnssAbilityTest::SetUp()
49 {
50     /*
51      * @tc.setup: Get system ability's pointer and get sa proxy object.
52      */
53     MockNativePermission();
54     ability_ = new (std::nothrow) GnssAbility();
55     EXPECT_NE(nullptr, ability_);
56     callbackStub_ = new (std::nothrow) GnssStatusCallbackHost();
57     EXPECT_NE(nullptr, callbackStub_);
58     nemaCallbackStub_ = new (std::nothrow) NmeaMessageCallbackHost();
59     EXPECT_NE(nullptr, nemaCallbackStub_);
60     cachedLocationCallbackStub_ = new (std::nothrow) CachedLocationsCallbackHost();
61     EXPECT_NE(nullptr, cachedLocationCallbackStub_);
62     proxy_ = new (std::nothrow) GnssAbilityProxy(ability_);
63     EXPECT_NE(nullptr, proxy_);
64 }
65 
TearDown()66 void GnssAbilityTest::TearDown()
67 {
68     /*
69      * @tc.teardown: release memory.
70      */
71     proxy_ = nullptr;
72     callbackStub_ = nullptr;
73 }
74 
MockNativePermission()75 void GnssAbilityTest::MockNativePermission()
76 {
77     const char *perms[] = {
78         ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(),
79         ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(),
80     };
81     NativeTokenInfoParams infoInstance = {
82         .dcapsNum = 0,
83         .permsNum = LOCATION_PERM_NUM,
84         .aclsNum = 0,
85         .dcaps = nullptr,
86         .perms = perms,
87         .acls = nullptr,
88         .processName = "GnssAbilityTest",
89         .aplStr = "system_basic",
90     };
91     uint64_t tokenId = GetAccessTokenId(&infoInstance);
92     SetSelfTokenID(tokenId);
93     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
94 }
95 
96 /*
97  * @tc.name: SendLocationRequest001
98  * @tc.desc: Build Request, marshall and unmarshall data Then Send it
99  * @tc.type: FUNC
100  */
101 HWTEST_F(GnssAbilityTest, SendLocationRequest001, TestSize.Level1)
102 {
103     GTEST_LOG_(INFO)
104         << "GnssAbilityTest, SendLocationRequest001, TestSize.Level1";
105     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] SendLocationRequest001 begin");
106     /*
107      * @tc.steps: step1. build location request data.
108      */
109     std::unique_ptr<WorkRecord> workRecord = std::make_unique<WorkRecord>();
110     int num = 2;
111     for (int i = 0; i < num; i++) {
112         int uid = i + 1;
113         int pid = i + 2;
114         int timeInterval = i;
115         std::string name = "nameForTest";
116         std::string uuid = std::to_string(CommonUtils::IntRandom(MIN_INT_RANDOM, MAX_INT_RANDOM));
117         workRecord->Add(uid, pid, name, timeInterval, uuid);
118     }
119     /*
120      * @tc.steps: step2. send location request
121      * @tc.expected: step2. no exception happens.
122      */
123     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SendLocationRequest(*workRecord));
124     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] SendLocationRequest001 end");
125 }
126 
127 /*
128  * @tc.name: SetEnableAndDisable001
129  * @tc.desc: Test disable and enable system ability
130  * @tc.type: FUNC
131  */
132 HWTEST_F(GnssAbilityTest, SetEnableAndDisable001, TestSize.Level1)
133 {
134     GTEST_LOG_(INFO)
135         << "GnssAbilityTest, SetEnableAndDisable001, TestSize.Level1";
136     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] SetEnableAndDisable001 begin");
137 
138     /*
139      * @tc.steps: step1.remove SA
140      * @tc.expected: step1. object1 is null.
141      */
142     MessageParcel data1;
143     data1.WriteBool(false); // if the state is false
144     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetEnable(data1.ReadBool()));
145 
146     /*
147      * @tc.steps: step2. test enable SA
148      * @tc.expected: step2. object2 is not null.
149      */
150     MessageParcel data2;
151     data2.WriteBool(true); // if the state is true
152     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetEnable(data2.ReadBool()));
153     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] SetEnableAndDisable001 end");
154 }
155 
156 /*
157  * @tc.name: RefrashRequirements001
158  * @tc.desc: Test refrash requirements
159  * @tc.type: FUNC
160  */
161 HWTEST_F(GnssAbilityTest, RefrashRequirements001, TestSize.Level1)
162 {
163     GTEST_LOG_(INFO)
164         << "GnssAbilityTest, RefrashRequirements001, TestSize.Level1";
165     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RefrashRequirements001 begin");
166     /*
167      * @tc.steps: step1. test refrash requirements
168      * @tc.expected: no exception happens.
169      */
170     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RefrashRequirements());
171     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RefrashRequirements001 end");
172 }
173 
174 /*
175  * @tc.name: RegisterGnssStatusCallback001
176  * @tc.desc: Test register gnss status callback if client is null
177  * @tc.type: FUNC
178  */
179 HWTEST_F(GnssAbilityTest, RegisterGnssStatusCallback001, TestSize.Level1)
180 {
181     GTEST_LOG_(INFO)
182         << "GnssAbilityTest, RegisterGnssStatusCallback001, TestSize.Level1";
183     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterGnssStatusCallback001 begin");
184     /*
185      * @tc.steps: step1.the client is null.
186      */
187     pid_t lastCallingUid = 1;
188     sptr<IRemoteObject> client = nullptr;
189 
190     /*
191      * @tc.steps: step2. test register gnss status callback
192      * @tc.expected: log info : "SendRegisterMsgToRemote callback is nullptr".
193      */
194     EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterGnssStatusCallback(client, lastCallingUid));
195     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterGnssStatusCallback001 end");
196 }
197 
198 /*
199  * @tc.name: RegisterAndUnregisterGnssStatusCallback001
200  * @tc.desc: Test register and unregister gnss status callback if client is not null
201  * @tc.type: FUNC
202  */
203 HWTEST_F(GnssAbilityTest, RegisterAndUnregisterGnssStatusCallback001, TestSize.Level1)
204 {
205     GTEST_LOG_(INFO)
206         << "GnssAbilityTest, RegisterAndUnregisterGnssStatusCallback001, TestSize.Level1";
207     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterAndUnregisterGnssStatusCallback001 begin");
208     /*
209      * @tc.steps: step1. give the last calling uid
210      */
211     pid_t lastCallingUid = 1;
212 
213     /*
214      * @tc.steps: step2. test register gnss status callback
215      * @tc.expected: no exception happens.
216      */
217     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterGnssStatusCallback(callbackStub_->AsObject(), lastCallingUid));
218 
219     /*
220      * @tc.steps: step3. test unregister gnss status callback
221      * @tc.expected: no exception happens
222      */
223     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->UnregisterGnssStatusCallback(callbackStub_->AsObject()));
224     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterAndUnregisterGnssStatusCallback001 end");
225 }
226 
227 /*
228  * @tc.name: UnregisterGnssStatusCallback001
229  * @tc.desc: Test unregister gnss status callback if client is null
230  * @tc.type: FUNC
231  */
232 HWTEST_F(GnssAbilityTest, UnregisterGnssStatusCallback001, TestSize.Level1)
233 {
234     GTEST_LOG_(INFO)
235         << "GnssAbilityTest, UnregisterGnssStatusCallback001, TestSize.Level1";
236     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] UnregisterGnssStatusCallback001 begin");
237     /*
238      * @tc.steps: step1.the client is null.
239      */
240     sptr<IRemoteObject> client = nullptr;
241 
242     /*
243      * @tc.steps: step2. test unregister gnss status callback
244      * @tc.expected: log info : "unregister an invalid gnssStatus callback".
245      */
246     EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->UnregisterGnssStatusCallback(client));
247     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] UnregisterGnssStatusCallback001 end");
248 }
249 
250 /*
251  * @tc.name: RegisterNmeaMessageCallback001
252  * @tc.desc: Test register nmea message callback if client is null
253  * @tc.type: FUNC
254  */
255 HWTEST_F(GnssAbilityTest, RegisterNmeaMessageCallback001, TestSize.Level1)
256 {
257     GTEST_LOG_(INFO)
258         << "GnssAbilityTest, RegisterNmeaMessageCallback001, TestSize.Level1";
259     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterNmeaMessageCallback001 begin");
260     /*
261      * @tc.steps: step1.the client is null.
262      */
263     pid_t uid = 1;
264     sptr<IRemoteObject> client = nullptr;
265 
266     /*
267      * @tc.steps: step2. test register nmea message callback
268      * @tc.expected: log info : "register an invalid nmea callback".
269      */
270     EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterNmeaMessageCallback(client, uid));
271     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterNmeaMessageCallback001 end");
272 }
273 
274 /*
275  * @tc.name: RegisterAndUnregisterNmeaMessageCallback001
276  * @tc.desc: Test register nmea message callback if client is not null
277  * @tc.type: FUNC
278  */
279 HWTEST_F(GnssAbilityTest, RegisterAndUnregisterNmeaMessageCallback001, TestSize.Level1)
280 {
281     GTEST_LOG_(INFO)
282         << "GnssAbilityTest, RegisterAndUnregisterNmeaMessageCallback001, TestSize.Level1";
283     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterAndUnregisterNmeaMessageCallback001 begin");
284     /*
285      * @tc.steps: step1.the client is not null.
286      */
287     pid_t uid = 1;
288 
289     /*
290      * @tc.steps: step2. test register nmea message callback
291      * @tc.expected: no exception happens
292      */
293     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->RegisterNmeaMessageCallback(nemaCallbackStub_->AsObject(), uid));
294 
295     /*
296      * @tc.steps: step3. test unregister nmea message callback
297      * @tc.expected: no exception happens.
298      */
299     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->UnregisterNmeaMessageCallback(nemaCallbackStub_->AsObject()));
300     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterAndUnregisterNmeaMessageCallback001 end");
301 }
302 
303 /*
304  * @tc.name: UnregisterNmeaMessageCallback001
305  * @tc.desc: Test unregister nmea message callback if client is null
306  * @tc.type: FUNC
307  */
308 HWTEST_F(GnssAbilityTest, UnregisterNmeaMessageCallback001, TestSize.Level1)
309 {
310     GTEST_LOG_(INFO)
311         << "GnssAbilityTest, UnregisterNmeaMessageCallback001, TestSize.Level1";
312     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] UnregisterNmeaMessageCallback001 begin");
313     /*
314      * @tc.steps: step1.the client is null.
315      */
316     sptr<IRemoteObject> client = nullptr;
317 
318     /*
319      * @tc.steps: step2. test unregister nmea message callback
320      * @tc.expected: log info : "unregister an invalid nmea callback".
321      */
322     EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->UnregisterNmeaMessageCallback(client));
323     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] UnregisterNmeaMessageCallback001 end");
324 }
325 
326 /*
327  * @tc.name: RegisterCachedCallback001
328  * @tc.desc: Test register cache call back
329  * @tc.type: FUNC
330  */
331 HWTEST_F(GnssAbilityTest, RegisterCachedCallback001, TestSize.Level1)
332 {
333     GTEST_LOG_(INFO)
334         << "GnssAbilityTest, RegisterCachedCallback001, TestSize.Level1";
335     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterCachedCallback001 begin");
336     /*
337      * @tc.steps: step1.prepare request config and the call back is null.
338      */
339     std::unique_ptr<CachedGnssLocationsRequest> requestConfig = std::make_unique<CachedGnssLocationsRequest>();
340     requestConfig->reportingPeriodSec = 100;
341     requestConfig->wakeUpCacheQueueFull = true;
342 
343     sptr<IRemoteObject> callback = nullptr;
344 
345     /*
346      * @tc.steps: step2. test register cached call back if call back is null.
347      * @tc.expected: log info : "register an invalid cached location callback"
348      */
349     EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->RegisterCachedCallback(requestConfig, callback));
350     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterCachedCallback001 end");
351 }
352 
353 /*
354  * @tc.name: RegisterCachedCallback002
355  * @tc.desc: Test register cache call back and the queue is not full.
356  * @tc.type: FUNC
357  */
358 HWTEST_F(GnssAbilityTest, RegisterCachedCallback003, TestSize.Level1)
359 {
360     GTEST_LOG_(INFO)
361         << "GnssAbilityTest, RegisterCachedCallback003, TestSize.Level1";
362     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterCachedCallback003 begin");
363     /*
364      * @tc.steps: step1.prepare request config and the call back is not null.
365      */
366     std::unique_ptr<CachedGnssLocationsRequest> requestConfig = std::make_unique<CachedGnssLocationsRequest>();
367     requestConfig->reportingPeriodSec = 100;
368     requestConfig->wakeUpCacheQueueFull = false;
369 
370     /*
371      * @tc.steps: step2. test register cached call back if call back is not null.
372      * @tc.expected: no exception happens
373      */
374     EXPECT_EQ(ERRCODE_NOT_SUPPORTED,
375         proxy_->RegisterCachedCallback(requestConfig, cachedLocationCallbackStub_->AsObject()));
376     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterCachedCallback003 end");
377 }
378 
379 /*
380  * @tc.name: RegisterAndUnregisterCachedCallback001
381  * @tc.desc: Test register and unregister cache call back and the queue is full.
382  * @tc.type: FUNC
383  */
384 HWTEST_F(GnssAbilityTest, RegisterAndUnregisterCachedCallback002, TestSize.Level1)
385 {
386     GTEST_LOG_(INFO)
387         << "GnssAbilityTest, RegisterAndUnregisterCachedCallback002, TestSize.Level1";
388     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterAndUnregisterCachedCallback002 begin");
389     /*
390      * @tc.steps: step1.prepare request config and the call back is not null.
391      */
392     std::unique_ptr<CachedGnssLocationsRequest> requestConfig = std::make_unique<CachedGnssLocationsRequest>();
393     requestConfig->reportingPeriodSec = 100;
394     requestConfig->wakeUpCacheQueueFull = true;
395 
396     /*
397      * @tc.steps: step2. test register cached call back if call back is not null.
398      * @tc.expected: no exception happens
399      */
400     EXPECT_EQ(ERRCODE_NOT_SUPPORTED,
401         proxy_->RegisterCachedCallback(requestConfig, cachedLocationCallbackStub_->AsObject()));
402 
403     /*
404      * @tc.steps: step3. test unregister cached call back if call back is not null.
405      * @tc.expected: no exception happens.
406      */
407     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->UnregisterCachedCallback(cachedLocationCallbackStub_->AsObject()));
408     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RegisterAndUnregisterCachedCallback002 end");
409 }
410 
411 /*
412  * @tc.name: UnregisterCachedCallback001
413  * @tc.desc: Test unregister cache call back and call back is null
414  * @tc.type: FUNC
415  */
416 HWTEST_F(GnssAbilityTest, UnregisterCachedCallback001, TestSize.Level1)
417 {
418     GTEST_LOG_(INFO)
419         << "GnssAbilityTest, UnregisterCachedCallback001, TestSize.Level1";
420     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] UnregisterCachedCallback001 begin");
421     /*
422      * @tc.steps: step1. the call back is null.
423      */
424     sptr<IRemoteObject> callback = nullptr;
425 
426     /*
427      * @tc.steps: step2. test unregister cached call back if call back is null.
428      * @tc.expected: log info : "register an invalid cached location callback"
429      */
430     EXPECT_EQ(ERRCODE_INVALID_PARAM, proxy_->UnregisterCachedCallback(callback));
431     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] UnregisterCachedCallback001 end");
432 }
433 
434 /*
435  * @tc.name: GetCachedGnssLocationsSize001
436  * @tc.desc: Test get cached gnss locations size
437  * @tc.type: FUNC
438  */
439 HWTEST_F(GnssAbilityTest, GetCachedGnssLocationsSize001, TestSize.Level1)
440 {
441     GTEST_LOG_(INFO)
442         << "GnssAbilityTest, GetCachedGnssLocationsSize001, TestSize.Level1";
443     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GetCachedGnssLocationsSize001 begin");
444     /*
445      * @tc.steps: step1. test get cached gnss locations size.
446      * @tc.expected: size equals -1.
447      */
448     int size = -1;
449     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->GetCachedGnssLocationsSize(size));
450     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GetCachedGnssLocationsSize001 end");
451 }
452 
453 /*
454  * @tc.name: FlushCachedGnssLocations001
455  * @tc.desc: Test unregister country code call back
456  * @tc.type: FUNC
457  */
458 HWTEST_F(GnssAbilityTest, FlushCachedGnssLocations001, TestSize.Level1)
459 {
460     GTEST_LOG_(INFO)
461         << "GnssAbilityTest, FlushCachedGnssLocations001, TestSize.Level1";
462     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] FlushCachedGnssLocations001 begin");
463     /*
464      * @tc.steps: step1. test flush cached gnss locations.
465      * @tc.expected: reply code unsupport
466      */
467     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->FlushCachedGnssLocations());
468     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] FlushCachedGnssLocations001 end");
469 }
470 
471 /*
472  * @tc.name: SendCommand001
473  * @tc.desc: Test send
474  * @tc.type: FUNC
475  */
476 HWTEST_F(GnssAbilityTest, SendCommand001, TestSize.Level1)
477 {
478     GTEST_LOG_(INFO)
479         << "GnssAbilityTest, SendCommand001, TestSize.Level1";
480     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] SendCommand001 begin");
481     /*
482      * @tc.steps: step1. build location command
483      */
484     std::unique_ptr<LocationCommand> locationCommand = std::make_unique<LocationCommand>();
485     locationCommand->scenario = 1;
486     locationCommand->command = true;
487 
488     /*
489      * @tc.steps: step2. test send command.
490      * @tc.expected: current function is empty, nothing happens
491      */
492     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SendCommand(locationCommand));
493     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] SendCommand001 end");
494 }
495 
496 /*
497  * @tc.name: AddFence001
498  * @tc.desc: Test add fence
499  * @tc.type: FUNC
500  */
501 HWTEST_F(GnssAbilityTest, AddFence001, TestSize.Level1)
502 {
503     GTEST_LOG_(INFO)
504         << "GnssAbilityTest, AddFence001, TestSize.Level1";
505     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AddFence001 begin");
506     /*
507      * @tc.steps: step1. build geo fence request
508      */
509     std::unique_ptr<GeofenceRequest> request = std::make_unique<GeofenceRequest>();
510     request->scenario = 2;
511     request->geofence.latitude = 35.1;
512     request->geofence.longitude = 40.2;
513     request->geofence.radius = 2.2;
514     request->geofence.expiration = 12.2;
515 
516     /*
517      * @tc.steps: step2. test add fence
518      * @tc.expected: no exception happens
519      */
520     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->AddFence(request));
521     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AddFence001 end");
522 }
523 
524 /*
525  * @tc.name: RemoveFence001
526  * @tc.desc: Test add fence
527  * @tc.type: FUNC
528  */
529 HWTEST_F(GnssAbilityTest, RemoveFence001, TestSize.Level1)
530 {
531     GTEST_LOG_(INFO)
532         << "GnssAbilityTest, RemoveFence001, TestSize.Level1";
533     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RemoveFence001 begin");
534     /*
535      * @tc.steps: step1. build geo fence request
536      */
537     std::unique_ptr<GeofenceRequest> request = std::make_unique<GeofenceRequest>();
538     request->scenario = 2;
539     request->geofence.latitude = 35.1;
540     request->geofence.longitude = 40.2;
541     request->geofence.radius = 2.2;
542     request->geofence.expiration = 12.2;
543 
544     /*
545      * @tc.steps: step2. test remove fence
546      * @tc.expected: no exception happens
547      */
548     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->RemoveFence(request));
549     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] RemoveFence001 end");
550 }
551 
552 HWTEST_F(GnssAbilityTest, GnssLocationMock001, TestSize.Level1)
553 {
554     GTEST_LOG_(INFO)
555         << "GnssAbilityTest, GnssLocationMock001, TestSize.Level1";
556     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssLocationMock001 begin");
557     int timeInterval = 0;
558     std::vector<std::shared_ptr<Location>> locations;
559     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->EnableMock());
560     EXPECT_EQ(true, ability_->IsMockEnabled());
561     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetMocked(timeInterval, locations));
562 
563     EXPECT_EQ(ERRCODE_SUCCESS, proxy_->DisableMock());
564     EXPECT_EQ(false, ability_->IsMockEnabled());
565     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->SetMocked(timeInterval, locations));
566     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssLocationMock001 begin");
567 }
568 
569 HWTEST_F(GnssAbilityTest, GnssOnStartAndOnStop001, TestSize.Level1)
570 {
571     GTEST_LOG_(INFO)
572         << "GnssAbilityTest, GnssOnStartAndOnStop001, TestSize.Level1";
573     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssOnStartAndOnStop001 begin");
574     ability_->OnStart(); // start ability
575     EXPECT_EQ(ServiceRunningState::STATE_NOT_START, ability_->QueryServiceState()); // mock will return nullptr
576 
577     ability_->OnStop(); // stop ability
578     EXPECT_EQ(ServiceRunningState::STATE_NOT_START, ability_->QueryServiceState()); // mock will return nullptr
579     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssOnStartAndOnStop001 end");
580 }
581 
582 HWTEST_F(GnssAbilityTest, GnssDump001, TestSize.Level1)
583 {
584     GTEST_LOG_(INFO)
585         << "GnssAbilityTest, GnssDump001, TestSize.Level1";
586     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssDump001 begin");
587     int32_t fd = 0;
588     std::vector<std::u16string> args;
589     std::u16string arg1 = Str8ToStr16("arg1");
590     args.emplace_back(arg1);
591     std::u16string arg2 = Str8ToStr16("arg2");
592     args.emplace_back(arg2);
593     std::u16string arg3 = Str8ToStr16("arg3");
594     args.emplace_back(arg3);
595     std::u16string arg4 = Str8ToStr16("arg4");
596     args.emplace_back(arg4);
597     EXPECT_EQ(ERR_OK, ability_->Dump(fd, args));
598 
599     std::vector<std::u16string> emptyArgs;
600     EXPECT_EQ(ERR_OK, ability_->Dump(fd, emptyArgs));
601 
602     std::vector<std::u16string> helpArgs;
603     std::u16string helpArg1 = Str8ToStr16(ARGS_HELP);
604     helpArgs.emplace_back(helpArg1);
605     EXPECT_EQ(ERR_OK, ability_->Dump(fd, helpArgs));
606     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssDump001 end");
607 }
608 
609 HWTEST_F(GnssAbilityTest, GnssSendReportMockLocationEvent001, TestSize.Level1)
610 {
611     GTEST_LOG_(INFO)
612         << "GnssAbilityTest, GnssSendReportMockLocationEvent001, TestSize.Level1";
613     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendReportMockLocationEvent001 begin");
614     ability_->SendReportMockLocationEvent(); // clear location mock
615 
616     int timeInterval = 0;
617     std::vector<std::shared_ptr<Location>> locations;
618     Parcel parcel;
619     parcel.WriteDouble(10.6); // latitude
620     parcel.WriteDouble(10.5); // longitude
621     parcel.WriteDouble(10.4); // altitude
622     parcel.WriteDouble(1.0); // accuracy
623     parcel.WriteDouble(5.0); // speed
624     parcel.WriteDouble(10); // direction
625     parcel.WriteInt64(1611000000); // timestamp
626     parcel.WriteInt64(1611000000); // time since boot
627     parcel.WriteString16(u"additions"); // additions
628     parcel.WriteInt64(1); // additionSize
629     parcel.WriteBool(true); // isFromMock is true
630     parcel.WriteInt32(1); // source type
631     parcel.WriteInt32(0); // floor no.
632     parcel.WriteDouble(1000.0); // floor acc
633     locations.push_back(Location::UnmarshallingShared(parcel));
634     EXPECT_EQ(ERRCODE_SUCCESS, ability_->EnableMock());
635     EXPECT_EQ(ERRCODE_SUCCESS, ability_->SetMocked(timeInterval, locations));
636     sleep(2);
637     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendReportMockLocationEvent001 end");
638 }
639 
640 HWTEST_F(GnssAbilityTest, GnssSendReportMockLocationEvent002, TestSize.Level1)
641 {
642     GTEST_LOG_(INFO)
643         << "GnssAbilityTest, GnssSendReportMockLocationEvent002, TestSize.Level1";
644     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendReportMockLocationEvent002 begin");
645     ability_->SendReportMockLocationEvent(); // clear location mock
646 
647     int timeInterval = 0;
648     std::vector<std::shared_ptr<Location>> locations;
649     Parcel parcel;
650     parcel.WriteDouble(10.6); // latitude
651     parcel.WriteDouble(10.5); // longitude
652     parcel.WriteDouble(10.4); // altitude
653     parcel.WriteDouble(1.0); // accuracy
654     parcel.WriteDouble(5.0); // speed
655     parcel.WriteDouble(10); // direction
656     parcel.WriteInt64(1611000000); // timestamp
657     parcel.WriteInt64(1611000000); // time since boot
658     parcel.WriteString16(u"additions"); // additions
659     parcel.WriteInt64(1); // additionSize
660     parcel.WriteBool(false); // isFromMock is false
661     parcel.WriteInt32(1); // source type
662     parcel.WriteInt32(0); // floor no.
663     parcel.WriteDouble(1000.0); // floor acc
664     locations.push_back(Location::UnmarshallingShared(parcel));
665     EXPECT_EQ(ERRCODE_SUCCESS, ability_->EnableMock());
666     EXPECT_EQ(ERRCODE_SUCCESS, ability_->SetMocked(timeInterval, locations));
667     sleep(2);
668     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendReportMockLocationEvent002 end");
669 }
670 
671 HWTEST_F(GnssAbilityTest, AddFenceAndRemoveFenceTest001, TestSize.Level1)
672 {
673     GTEST_LOG_(INFO)
674         << "GnssAbilityTest, AddFenceAndRemoveFenceTest001, TestSize.Level1";
675     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AddFenceAndRemoveFenceTest001 begin");
676     std::unique_ptr<GeofenceRequest> fence = std::make_unique<GeofenceRequest>();
677     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, ability_->AddFence(fence));
678     EXPECT_EQ(ERRCODE_NOT_SUPPORTED, ability_->RemoveFence(fence));
679     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AddFenceAndRemoveFenceTest001 end");
680 }
681 
682 HWTEST_F(GnssAbilityTest, GnssAbilityReportSv001, TestSize.Level1)
683 {
684     GTEST_LOG_(INFO)
685         << "GnssAbilityTest, GnssAbilityReportSv001, TestSize.Level1";
686     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssAbilityReportSv001 begin");
687     std::unique_ptr<SatelliteStatus> status = std::make_unique<SatelliteStatus>();
688     MessageParcel parcel;
689     int sateNum = 2;
690     parcel.WriteInt64(2); // satellitesNumber
691     for (int i = 0; i < sateNum; i++) {
692         parcel.WriteInt64(i); // satelliteId
693         parcel.WriteDouble(i + 1.0); // carrierToNoiseDensity
694         parcel.WriteDouble(i + 2.0); // altitude
695         parcel.WriteDouble(i + 3.0); // azimuth
696         parcel.WriteDouble(i + 4.0); // carrierFrequency
697     }
698     ASSERT_TRUE(status != nullptr);
699     status->ReadFromParcel(parcel);
700     ASSERT_TRUE(ability_ != nullptr);
701     ability_->ReportSv(status);
702     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssAbilityReportSv001 end");
703 }
704 
705 #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
706 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestSetUpAgnssDataLink001, TestSize.Level1)
707 {
708     GTEST_LOG_(INFO)
709         << "GnssAbilityTest, AGnssEventCallbackRequestSetUpAgnssDataLink001, TestSize.Level1";
710     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestSetUpAgnssDataLink001 begin");
711     sptr<IAGnssCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
712     EXPECT_NE(nullptr, agnssCallback);
713     AGnssDataLinkRequest request;
714     request.agnssType = HDI::Location::Agnss::V1_0::AGNSS_TYPE_SUPL;
715     request.setUpType = HDI::Location::Agnss::V1_0::ESTABLISH_DATA_CONNECTION;
716     EXPECT_EQ(ERR_OK, agnssCallback->RequestSetUpAgnssDataLink(request));
717     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestSetUpAgnssDataLink001 end");
718 }
719 
720 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestSubscriberSetId001, TestSize.Level1)
721 {
722     GTEST_LOG_(INFO)
723         << "GnssAbilityTest, AGnssEventCallbackRequestSubscriberSetId001, TestSize.Level1";
724     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestSubscriberSetId001 begin");
725     sptr<IAGnssCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
726     EXPECT_NE(nullptr, agnssCallback);
727     SubscriberSetIdType type = HDI::Location::Agnss::V1_0::SETID_TYPE_IMSI;
728     EXPECT_EQ(ERR_OK, agnssCallback->RequestSubscriberSetId(type));
729     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestSubscriberSetId001 end");
730 }
731 
732 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo001, TestSize.Level1)
733 {
734     GTEST_LOG_(INFO)
735         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo001, TestSize.Level1";
736     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo001 begin");
737     sptr<IAGnssCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
738     EXPECT_CALL(MockICellularDataManager::GetInstance(), GetDefaultCellularDataSlotId).WillRepeatedly(Return(-1));
739     EXPECT_NE(nullptr, agnssCallback);
740     EXPECT_EQ(ERR_OK, agnssCallback->RequestAgnssRefInfo());
741     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo001 end");
742 }
743 
744 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo002, TestSize.Level1)
745 {
746     GTEST_LOG_(INFO)
747         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo002, TestSize.Level1";
748     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo002 begin");
749     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
750     EXPECT_NE(nullptr, agnssCallback);
751     AGnssRefInfo refInfo;
752     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
753     sptr<Telephony::GsmCellInformation> gsmCellInformation = new Telephony::GsmCellInformation();
754     gsmCellInformation->Init(0, 0, 0);
755     agnssCallback->JudgmentDataGsm(refInfo, gsmCellInformation);
756     EXPECT_EQ(HDI::Location::Agnss::V1_0::CELLID_TYPE_GSM, refInfo.cellId.type);
757     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo002 end");
758 }
759 
760 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo003, TestSize.Level1)
761 {
762     GTEST_LOG_(INFO)
763         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo003, TestSize.Level1";
764     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo003 begin");
765     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
766     EXPECT_NE(nullptr, agnssCallback);
767     AGnssRefInfo refInfo;
768     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
769     sptr<Telephony::GsmCellInformation> gsmCellInformation = nullptr;
770     agnssCallback->JudgmentDataGsm(refInfo, gsmCellInformation);
771     EXPECT_NE(HDI::Location::Agnss::V1_0::CELLID_TYPE_GSM, refInfo.cellId.type);
772     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo003 begin");
773 }
774 
775 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo004, TestSize.Level1)
776 {
777     GTEST_LOG_(INFO)
778         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo004, TestSize.Level1";
779     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo004 begin");
780     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
781     EXPECT_NE(nullptr, agnssCallback);
782     AGnssRefInfo refInfo;
783     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
784     sptr<Telephony::LteCellInformation> lteCellInformation = new Telephony::LteCellInformation();
785     lteCellInformation->Init(0, 0, 0);
786     agnssCallback->JudgmentDataLte(refInfo, lteCellInformation);
787     EXPECT_EQ(HDI::Location::Agnss::V1_0::CELLID_TYPE_LTE, refInfo.cellId.type);
788     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo004 begin");
789 }
790 
791 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo005, TestSize.Level1)
792 {
793     GTEST_LOG_(INFO)
794         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo005, TestSize.Level1";
795     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo005 begin");
796     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
797     EXPECT_NE(nullptr, agnssCallback);
798     AGnssRefInfo refInfo;
799     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
800     sptr<Telephony::LteCellInformation> lteCellInformation = nullptr;
801     agnssCallback->JudgmentDataLte(refInfo, lteCellInformation);
802     EXPECT_NE(HDI::Location::Agnss::V1_0::CELLID_TYPE_LTE, refInfo.cellId.type);
803     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo005 begin");
804 }
805 
806 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo006, TestSize.Level1)
807 {
808     GTEST_LOG_(INFO)
809         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo006, TestSize.Level1";
810     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo006 begin");
811     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
812     EXPECT_NE(nullptr, agnssCallback);
813     AGnssRefInfo refInfo;
814     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
815     sptr<Telephony::WcdmaCellInformation> umtsCellInformation = new Telephony::WcdmaCellInformation();
816     umtsCellInformation->Init(0, 0, 0);
817     agnssCallback->JudgmentDataUmts(refInfo, umtsCellInformation);
818     EXPECT_EQ(HDI::Location::Agnss::V1_0::CELLID_TYPE_UMTS, refInfo.cellId.type);
819     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo006 begin");
820 }
821 
822 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo007, TestSize.Level1)
823 {
824     GTEST_LOG_(INFO)
825         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo007, TestSize.Level1";
826     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo007 begin");
827     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
828     EXPECT_NE(nullptr, agnssCallback);
829     AGnssRefInfo refInfo;
830     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
831     sptr<Telephony::WcdmaCellInformation> umtsCellInformation = nullptr;
832     agnssCallback->JudgmentDataUmts(refInfo, umtsCellInformation);
833     EXPECT_NE(HDI::Location::Agnss::V1_0::CELLID_TYPE_UMTS, refInfo.cellId.type);
834     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo007 begin");
835 }
836 
837 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo008, TestSize.Level1)
838 {
839     GTEST_LOG_(INFO)
840         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo008, TestSize.Level1";
841     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo008 begin");
842     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
843     EXPECT_NE(nullptr, agnssCallback);
844     AGnssRefInfo refInfo;
845     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
846     sptr<Telephony::NrCellInformation> nrCellInformation = new Telephony::NrCellInformation();
847     nrCellInformation->Init(0, 0, 0);
848     agnssCallback->JudgmentDataNr(refInfo, nrCellInformation);
849     EXPECT_EQ(HDI::Location::Agnss::V1_0::CELLID_TYPE_NR, refInfo.cellId.type);
850     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo008 begin");
851 }
852 
853 HWTEST_F(GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo009, TestSize.Level1)
854 {
855     GTEST_LOG_(INFO)
856         << "GnssAbilityTest, AGnssEventCallbackRequestAgnssRefInfo009, TestSize.Level1";
857     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo009 begin");
858     sptr<AGnssEventCallback> agnssCallback = new (std::nothrow) AGnssEventCallback();
859     EXPECT_NE(nullptr, agnssCallback);
860     AGnssRefInfo refInfo;
861     refInfo.type = HDI::Location::Agnss::V1_0::ANSS_REF_INFO_TYPE_CELLID;
862     sptr<Telephony::NrCellInformation> nrCellInformation = nullptr;
863     agnssCallback->JudgmentDataNr(refInfo, nrCellInformation);
864     EXPECT_NE(HDI::Location::Agnss::V1_0::CELLID_TYPE_NR, refInfo.cellId.type);
865     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] AGnssEventCallbackRequestAgnssRefInfo009 begin");
866 }
867 #endif
868 
869 HWTEST_F(GnssAbilityTest, GnssEventCallbackReportLocation001, TestSize.Level1)
870 {
871     GTEST_LOG_(INFO)
872         << "GnssAbilityTest, GnssEventCallbackReportLocation001, TestSize.Level1";
873     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportLocation001 begin");
874     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
875     EXPECT_NE(nullptr, gnssCallback);
876     LocationInfo locationInfo;
877     locationInfo.latitude = 1.0;
878     locationInfo.longitude = 2.0;
879     locationInfo.altitude = 1.0;
880     locationInfo.accuracy = 1.0;
881     locationInfo.speed = 1.0;
882     locationInfo.direction= 1.0;
883     locationInfo.timeStamp = 1000000000;
884     locationInfo.timeSinceBoot = 1000000000;
885     gnssCallback->ReportLocation(locationInfo);
886     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportLocation001 end");
887 }
888 
889 HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssWorkingStatus001, TestSize.Level1)
890 {
891     GTEST_LOG_(INFO)
892         << "GnssAbilityTest, GnssEventCallbackReportGnssWorkingStatus001, TestSize.Level1";
893     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssWorkingStatus001 begin");
894     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
895     EXPECT_NE(nullptr, gnssCallback);
896     GnssWorkingStatus status = HDI::Location::Gnss::V1_0::GNSS_STATUS_NONE;
897     gnssCallback->ReportGnssWorkingStatus(status);
898     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssWorkingStatus001 end");
899 }
900 
901 HWTEST_F(GnssAbilityTest, GnssEventCallbackReportNmea001, TestSize.Level1)
902 {
903     GTEST_LOG_(INFO)
904         << "GnssAbilityTest, GnssEventCallbackReportNmea001, TestSize.Level1";
905     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportNmea001 begin");
906     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
907     EXPECT_NE(nullptr, gnssCallback);
908     gnssCallback->ReportNmea(0, "nmea", 0);
909     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportNmea001 end");
910 }
911 
912 HWTEST_F(GnssAbilityTest, GnssEventCallbackReportGnssCapabilities001, TestSize.Level1)
913 {
914     GTEST_LOG_(INFO)
915         << "GnssAbilityTest, GnssEventCallbackReportGnssCapabilities001, TestSize.Level1";
916     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssCapabilities001 begin");
917     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
918     EXPECT_NE(nullptr, gnssCallback);
919     GnssCapabilities capabilities = HDI::Location::Gnss::V1_0::GNSS_CAP_SUPPORT_MSB;
920     gnssCallback->ReportGnssCapabilities(capabilities);
921     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportGnssCapabilities001 end");
922 }
923 
924 HWTEST_F(GnssAbilityTest, GnssEventCallbackReportSatelliteStatusInfo002, TestSize.Level1)
925 {
926     GTEST_LOG_(INFO)
927         << "GnssAbilityTest, GnssEventCallbackReportSatelliteStatusInfo002, TestSize.Level1";
928     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportSatelliteStatusInfo002 begin");
929     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
930     EXPECT_NE(nullptr, gnssCallback);
931     SatelliteStatusInfo statusInfo;
932     statusInfo.satellitesNumber = 0;
933     statusInfo.flags =
934         HDI::Location::Gnss::V1_0::SATELLITES_STATUS_HAS_EPHEMERIS_DATA;
935     gnssCallback->ReportSatelliteStatusInfo(statusInfo);
936     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportSatelliteStatusInfo002 end");
937 }
938 
939 HWTEST_F(GnssAbilityTest, GnssEventCallbackRequestGnssReferenceInfo001, TestSize.Level1)
940 {
941     GTEST_LOG_(INFO)
942         << "GnssAbilityTest, GnssEventCallbackRequestGnssReferenceInfo001, TestSize.Level1";
943     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackRequestGnssReferenceInfo001 begin");
944     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
945     EXPECT_NE(nullptr, gnssCallback);
946     GnssRefInfoType type = HDI::Location::Gnss::V1_0::GNSS_REF_INFO_TIME;
947     gnssCallback->RequestGnssReferenceInfo(type);
948     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackRequestGnssReferenceInfo001 end");
949 }
950 
951 HWTEST_F(GnssAbilityTest, GnssEventCallbackRequestPredictGnssData001, TestSize.Level1)
952 {
953     GTEST_LOG_(INFO)
954         << "GnssAbilityTest, GnssEventCallbackRequestPredictGnssData001, TestSize.Level1";
955     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackRequestPredictGnssData001 begin");
956     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
957     EXPECT_NE(nullptr, gnssCallback);
958     gnssCallback->RequestPredictGnssData();
959     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackRequestPredictGnssData001 end");
960 }
961 
962 HWTEST_F(GnssAbilityTest, GnssEventCallbackReportCachedLocation001, TestSize.Level1)
963 {
964     GTEST_LOG_(INFO)
965         << "GnssAbilityTest, GnssEventCallbackReportCachedLocation001, TestSize.Level1";
966     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportCachedLocation001 begin");
967     sptr<IGnssCallback> gnssCallback = new (std::nothrow) GnssEventCallback();
968     EXPECT_NE(nullptr, gnssCallback);
969     std::vector<LocationInfo> gnssLocations;
970     LocationInfo locationInfo;
971     locationInfo.latitude = 1.0;
972     locationInfo.longitude = 2.0;
973     locationInfo.altitude = 1.0;
974     locationInfo.accuracy = 1.0;
975     locationInfo.speed = 1.0;
976     locationInfo.direction= 1.0;
977     locationInfo.timeStamp = 1000000000;
978     locationInfo.timeSinceBoot = 1000000000;
979     gnssLocations.push_back(locationInfo);
980     gnssCallback->ReportCachedLocation(gnssLocations);
981     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssEventCallbackReportCachedLocation001 end");
982 }
983 
984 HWTEST_F(GnssAbilityTest, GnssOnStart001, TestSize.Level1)
985 {
986     GTEST_LOG_(INFO)
987         << "GnssAbilityTest, GnssOnStart001, TestSize.Level1";
988     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssOnStart001 begin");
989     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
990     ASSERT_TRUE(gnssAbility != nullptr);
991     gnssAbility->state_ = ServiceRunningState::STATE_RUNNING;
992     gnssAbility->OnStart();
993     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssOnStart001 end");
994 }
995 
996 HWTEST_F(GnssAbilityTest, GnssSendLocationRequest001, TestSize.Level1)
997 {
998     GTEST_LOG_(INFO)
999         << "GnssAbilityTest, GnssSendLocationRequest001, TestSize.Level1";
1000     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendLocationRequest001 begin");
1001     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1002     ASSERT_TRUE(gnssAbility != nullptr);
1003     WorkRecord workrecord;
1004     gnssAbility->SendLocationRequest(workrecord);
1005     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendLocationRequest001 end");
1006 }
1007 
1008 HWTEST_F(GnssAbilityTest, GnssDisableGnss001, TestSize.Level1)
1009 {
1010     GTEST_LOG_(INFO)
1011         << "GnssAbilityTest, GnssDisableGnss001, TestSize.Level1";
1012     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssDisableGnss001 begin");
1013     sptr<GnssAbility> gnssAbility1 = new (std::nothrow) GnssAbility();
1014     ASSERT_TRUE(gnssAbility1 != nullptr);
1015     gnssAbility1->gnssWorkingStatus_ = GNSS_STATUS_SESSION_BEGIN;
1016     gnssAbility1->DisableGnss();
1017 
1018     sptr<GnssAbility> gnssAbility2 = new (std::nothrow) GnssAbility();
1019     ASSERT_TRUE(gnssAbility2 != nullptr);
1020     gnssAbility2->gnssWorkingStatus_ = GNSS_STATUS_ENGINE_OFF;
1021     gnssAbility2->DisableGnss();
1022     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssDisableGnss001 end");
1023 }
1024 
1025 HWTEST_F(GnssAbilityTest, GnssStartGnss001, TestSize.Level1)
1026 {
1027     GTEST_LOG_(INFO)
1028         << "GnssAbilityTest, GnssStartGnss001, TestSize.Level1";
1029     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssStartGnss001 begin");
1030     sptr<GnssAbility> gnssAbility1 = new (std::nothrow) GnssAbility();
1031     ASSERT_TRUE(gnssAbility1 != nullptr);
1032     gnssAbility1->gnssWorkingStatus_ = GNSS_STATUS_SESSION_BEGIN;
1033     gnssAbility1->StartGnss();
1034 
1035     sptr<GnssAbility> gnssAbility2 = new (std::nothrow) GnssAbility();
1036     ASSERT_TRUE(gnssAbility2 != nullptr);
1037     gnssAbility2->gnssWorkingStatus_ = GNSS_STATUS_ENGINE_OFF;
1038     gnssAbility2->StartGnss();
1039     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssStartGnss001 end");
1040 }
1041 
1042 HWTEST_F(GnssAbilityTest, GnssInit001, TestSize.Level1)
1043 {
1044     GTEST_LOG_(INFO)
1045         << "GnssAbilityTest, GnssInit001, TestSize.Level1";
1046     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssInit001 begin");
1047     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1048     ASSERT_TRUE(gnssAbility != nullptr);
1049     gnssAbility->registerToAbility_ = true;
1050     EXPECT_EQ(true, gnssAbility->Init());
1051     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssInit001 end");
1052 }
1053 
1054 HWTEST_F(GnssAbilityTest, GnssRequestRecord001, TestSize.Level1)
1055 {
1056     GTEST_LOG_(INFO)
1057         << "GnssAbilityTest, GnssRequestRecord001, TestSize.Level1";
1058     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssRequestRecord001 begin");
1059     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1060     ASSERT_TRUE(gnssAbility != nullptr);
1061     std::unique_ptr<WorkRecord> workRecord = std::make_unique<WorkRecord>();
1062     gnssAbility->isHdiConnected_ = false;
1063     gnssAbility->RequestRecord(*workRecord, false);
1064     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssRequestRecord001 end");
1065 }
1066 
1067 HWTEST_F(GnssAbilityTest, GnssReConnectHdi001, TestSize.Level1)
1068 {
1069     GTEST_LOG_(INFO)
1070         << "GnssAbilityTest, GnssReConnectHdi001, TestSize.Level1";
1071     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssReConnectHdi001 begin");
1072     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1073     ASSERT_TRUE(gnssAbility != nullptr);
1074 
1075     gnssAbility->isHdiConnected_ = true;
1076     gnssAbility->ReConnectHdi();
1077     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssReConnectHdi001 end");
1078 }
1079 
1080 #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
1081 HWTEST_F(GnssAbilityTest, GnssSetRefInfo001, TestSize.Level1)
1082 {
1083     GTEST_LOG_(INFO)
1084         << "GnssAbilityTest, GnssSetRefInfo001, TestSize.Level1";
1085     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSetRefInfo001 begin");
1086     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1087     ASSERT_TRUE(gnssAbility != nullptr);
1088     AGnssRefInfo refInfo;
1089     gnssAbility->SetRefInfo(refInfo);
1090     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSetRefInfo001 end");
1091 }
1092 #endif
1093 
1094 HWTEST_F(GnssAbilityTest, GnssSendReportMockLocationEvent003, TestSize.Level1)
1095 {
1096     GTEST_LOG_(INFO)
1097         << "GnssAbilityTest, GnssSendReportMockLocationEvent003, TestSize.Level1";
1098     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendReportMockLocationEvent003 begin");
1099     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1100     ASSERT_TRUE(gnssAbility != nullptr);
1101     gnssAbility->gnssHandler_  = nullptr;
1102     gnssAbility->SendReportMockLocationEvent();
1103     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendReportMockLocationEvent003 end");
1104 }
1105 
1106 HWTEST_F(GnssAbilityTest, GnssSendMessage001, TestSize.Level1)
1107 {
1108     GTEST_LOG_(INFO)
1109         << "GnssAbilityTest, GnssSendMessage001, TestSize.Level1";
1110     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage001 begin");
1111     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1112     ASSERT_TRUE(gnssAbility != nullptr);
1113     MessageParcel requestParcel;
1114     requestParcel.WriteInterfaceToken(u"location.INetworkAbility");
1115     requestParcel.WriteBuffer("data", 4);
1116     requestParcel.RewindRead(0);
1117 
1118     MessageParcel reply;
1119     gnssAbility->gnssHandler_  = nullptr;
1120     gnssAbility->SendMessage(0, requestParcel, reply);
1121     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssSendMessage001 end");
1122 }
1123 
1124 
1125 HWTEST_F(GnssAbilityTest, GnssRegisterLocationHdiDeathRecipient001, TestSize.Level1)
1126 {
1127     GTEST_LOG_(INFO)
1128         << "GnssAbilityTest, GnssRegisterLocationHdiDeathRecipient001, TestSize.Level1";
1129     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssRegisterLocationHdiDeathRecipient001 begin");
1130     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1131     ASSERT_TRUE(gnssAbility != nullptr);
1132     gnssAbility->gnssHandler_  = nullptr;
1133     gnssAbility->RegisterLocationHdiDeathRecipient();
1134     LBSLOGI(GNSS_TEST, "[GnssAbilityTest] GnssRegisterLocationHdiDeathRecipient001 end");
1135 }
1136 
1137 HWTEST_F(GnssAbilityTest, SubAbilityCommonGetRequestNum001, TestSize.Level1)
1138 {
1139     GTEST_LOG_(INFO)
1140         << "SubAbilityCommonTest, GetRequestNum001, TestSize.Level1";
1141     LBSLOGI(LOCATOR, "[SubAbilityCommonTest] GetRequestNum001 begin");
1142     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1143     gnssAbility->newRecord_ = nullptr;
1144     gnssAbility->GetRequestNum();
1145 
1146     gnssAbility->newRecord_ = std::make_unique<WorkRecord>();
1147     std::shared_ptr<WorkRecord> workRecord = std::make_shared<WorkRecord>();
1148     int num = 2;
1149     for (int i = 0; i < num; i++) {
1150         int uid = i + 1;
1151         int pid = i + 2;
1152         int timeInterval = i;
1153         std::string name = "nameForTest";
1154         std::string uuid = "uuidForTest";
1155         workRecord->Add(uid, pid, name, timeInterval, uuid);
1156     }
1157     gnssAbility->newRecord_->Set(*workRecord);
1158     gnssAbility->GetRequestNum();
1159 
1160     gnssAbility->newRecord_ = nullptr;
1161     gnssAbility->GetRequestNum();
1162 
1163     gnssAbility->lastRecord_->Add(0, 0, "nameForTest", 0, "uuidForTest");
1164     gnssAbility->HandleRemoveRecord(*workRecord);
1165 
1166     gnssAbility->lastRecord_->Clear();
1167     gnssAbility->lastRecord_->Set(*workRecord);
1168     gnssAbility->HandleAddRecord(*workRecord);
1169     LBSLOGI(LOCATOR, "[SubAbilityCommonTest] GetRequestNum001 end");
1170 }
1171 
1172 HWTEST_F(GnssAbilityTest, SubAbilityCommonHandleSelfRequest001, TestSize.Level1)
1173 {
1174     GTEST_LOG_(INFO)
1175         << "SubAbilityCommonTest, HandleSelfRequest001, TestSize.Level1";
1176     LBSLOGI(LOCATOR, "[SubAbilityCommonTest] HandleSelfRequest001 begin");
1177     sptr<GnssAbility> gnssAbility = new (std::nothrow) GnssAbility();
1178     gnssAbility->HandleSelfRequest(0, 0, false);
1179 
1180     gnssAbility->GetTimeIntervalMock();
1181     LBSLOGI(LOCATOR, "[SubAbilityCommonTest] HandleSelfRequest001 end");
1182 }
1183 }  // namespace Location
1184 }  // namespace OHOS
1185 #endif // FEATURE_GNSS_SUPPORT
1186