• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
17 #include "idevmgr_hdi.h"
18 #include <memory>
19 #include <iostream>
20 #include <osal_mem.h>
21 #include "hdf_sbuf.h"
22 #include <cmath>
23 #include <cstdio>
24 #include <unistd.h>
25 #include <gtest/gtest.h>
26 #include <securec.h>
27 #include "hdf_base.h"
28 #include "hdf_log.h"
29 #include "osal_time.h"
30 #include "v1_0/ignss_interface.h"
31 #include "gnss_interface_impl.h"
32 #include "gnss_callback_impl.h"
33 
34 
35 using namespace OHOS::HDI::Location::Gnss::V1_0;
36 using namespace std;
37 using namespace testing::ext;
38 
39 namespace {
40     sptr<IGnssInterface> g_ignssHci = nullptr;
41     constexpr const char *AGNSS_SERVICE_NAME = "agnss_interface_service";
42     constexpr const char *GNSS_SERVICE_NAME = "gnss_interface_service";
43     constexpr const char *GEOFENCE_SERVICE_NAME = "geofence_interface_service";
44 }
45 
46 class LocationGnssTest : public testing::Test {
47 public:
48     static void SetUpTestCase();
49     static void TearDownTestCase();
50     void SetUp();
51     void TearDown();
52 };
53 
54 
ReportLocation(const LocationInfo & location)55 int32_t GnssCallbackImpl::ReportLocation(const LocationInfo& location)
56 {
57     if (location.timeSinceBoot != 0) {
58         printf("Location success!!");
59         return HDF_SUCCESS;
60     }
61     else{
62         printf("Location fail!!");
63         return HDF_FAILURE;
64     }
65 }
66 
67 
ReportGnssWorkingStatus(GnssWorkingStatus status)68 int32_t GnssCallbackImpl::ReportGnssWorkingStatus(GnssWorkingStatus status)
69 {
70     if (status == GnssWorkingStatus::GNSS_STATUS_NONE) {
71         printf("GNSS_STATUS_NONE");
72         return HDF_SUCCESS;
73     }
74     else if(status == GnssWorkingStatus::GNSS_STATUS_SESSION_BEGIN){
75         printf("GNSS_STATUS_SESSION_BEGIN");
76         return HDF_SUCCESS;
77     }
78     else if(status == GnssWorkingStatus::GNSS_STATUS_SESSION_END){
79         printf("GNSS_STATUS_SESSION_END");
80         return HDF_SUCCESS;
81     }
82     else if(status == GnssWorkingStatus::GNSS_STATUS_ENGINE_ON){
83         printf("GNSS_STATUS_ENGINE_ON");
84         return HDF_SUCCESS;
85     }
86     else if(status == GnssWorkingStatus::GNSS_STATUS_ENGINE_OFF){
87         printf("GNSS_STATUS_ENGINE_OFF");
88         return HDF_SUCCESS;
89     }
90     else{
91         printf("Gnss status fail");
92         return HDF_FAILURE;
93     }
94 }
95 
ReportNmea(int64_t timestamp,const std::string & nmea,int32_t length)96 int32_t GnssCallbackImpl::ReportNmea(int64_t timestamp, const std::string& nmea, int32_t length)
97 {
98     if (length >= 0) {
99         printf("Report nmea success");
100         return HDF_SUCCESS;
101     }
102     else{
103         printf("Report nmea fail");
104         return HDF_FAILURE;
105     }
106 }
107 
ReportGnssCapabilities(GnssCapabilities capabilities)108 int32_t GnssCallbackImpl::ReportGnssCapabilities(GnssCapabilities capabilities)
109 {
110     return HDF_SUCCESS;
111 }
112 
ReportSatelliteStatusInfo(const SatelliteStatusInfo & info)113 int32_t GnssCallbackImpl::ReportSatelliteStatusInfo(const SatelliteStatusInfo& info)
114 {
115     if (info.satellitesNumber <= 0) {
116         printf("SvStatusCallback, satellites_num <= 0!");
117         return HDF_ERR_INVALID_PARAM;
118     }
119     if (((info.carrierFrequencies).size()) > 0) {
120         printf("Get satellite info success!!");
121         return HDF_SUCCESS;
122     }
123     else{
124         printf("Get satellite info fail!!");
125         return HDF_FAILURE;
126     }
127 }
128 
RequestGnssReferenceInfo(GnssRefInfoType type)129 int32_t GnssCallbackImpl::RequestGnssReferenceInfo(GnssRefInfoType type)
130 {
131     return HDF_SUCCESS;
132 }
133 
RequestPredictGnssData()134 int32_t GnssCallbackImpl::RequestPredictGnssData()
135 {
136     return HDF_SUCCESS;
137 }
138 
ReportCachedLocation(const std::vector<LocationInfo> & gnssLocations)139 int32_t GnssCallbackImpl::ReportCachedLocation(const std::vector<LocationInfo>& gnssLocations)
140 {
141     return HDF_SUCCESS;
142 }
143 
144 
145 
SetUpTestCase()146 void LocationGnssTest::SetUpTestCase()
147 {
148     auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get();
149     if (devmgr == nullptr) {
150         printf("fail to get devmgr.");
151         return;
152     }
153     if (devmgr->LoadDevice(GNSS_SERVICE_NAME) != 0) {
154         printf("Load gnss service failed!");
155         return;
156     }
157     if (devmgr->LoadDevice(AGNSS_SERVICE_NAME) != 0) {
158         printf("Load agnss service failed!");
159         return;
160     }
161     if (devmgr->LoadDevice(GEOFENCE_SERVICE_NAME) != 0) {
162         printf("Load geofence service failed!");
163         return;
164     }
165     g_ignssHci = IGnssInterface::Get();
166 }
167 
TearDownTestCase()168 void LocationGnssTest::TearDownTestCase()
169 {
170     auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get();
171     if (devmgr == nullptr) {
172         printf("fail to get devmgr.");
173         return;
174     }
175     if (devmgr->UnloadDevice(GNSS_SERVICE_NAME) != 0) {
176         printf("Load gnss service failed!");
177         return;
178     }
179     if (devmgr->UnloadDevice(AGNSS_SERVICE_NAME) != 0) {
180         printf("Load agnss service failed!");
181         return;
182     }
183     if (devmgr->UnloadDevice(GEOFENCE_SERVICE_NAME) != 0) {
184         printf("Load geofence service failed!");
185         return;
186     }
187 }
188 
SetUp()189 void LocationGnssTest::SetUp()
190 {
191 }
192 
TearDown()193 void LocationGnssTest::TearDown()
194 {
195 }
196 
197 
198 /**
199   * @tc.name: EnableGnss0100
200   * @tc.desc: Enable the GNSS module and transmit the callback of the upper layer to the GNSS module..
201   * @tc.type: FUNC
202   */
203 HWTEST_F(LocationGnssTest, SUB_DriverSystem_EnableGnss_0100, TestSize.Level1)
204 {
205     if (g_ignssHci == nullptr) {
206         ASSERT_NE(nullptr, g_ignssHci);
207         return;
208     }
209     sptr<IGnssCallback> gnss_callback = new (std::nothrow) GnssCallbackImpl();
210     if (gnss_callback == nullptr) {
211         ASSERT_NE(nullptr, gnss_callback);
212         return;
213     }
214     int32_t ret = g_ignssHci->EnableGnss(gnss_callback);
215     EXPECT_EQ(HDF_SUCCESS, ret);
216     GnssStartType starttype = GnssStartType::GNSS_START_TYPE_NORMAL;
217     int32_t ret1 = g_ignssHci->StartGnss(starttype);
218     EXPECT_EQ(HDF_SUCCESS, ret1);
219 }
220 
221 
222 /**
223   * @tc.name: SetGnssConfigPara0100
224   * @tc.desc: Setting gnss configuration parameters.
225   * @tc.type: FUNC
226   */
227 HWTEST_F(LocationGnssTest, SUB_DriverSystem_SetGnssConfigPara_0100, TestSize.Level1)
228 {
229     if (g_ignssHci == nullptr) {
230         ASSERT_NE(nullptr, g_ignssHci);
231         return;
232     }
233     GnssConfigPara para;
234     para.gnssBasic.minInterval = 10;
235     para.gnssBasic.accuracy = 50;
236     para.gnssBasic.firstFixTime = 300;
237     para.gnssBasic.isPeriodicPositioning = true;
238     para.gnssBasic.gnssMode = GnssWorkingMode::GNSS_WORKING_MODE_STANDALONE;
239     para.gnssCaching.interval = 20;
240     para.gnssCaching.fifoFullNotify = true;
241     int32_t ret = g_ignssHci->SetGnssConfigPara(para);
242     EXPECT_EQ(HDF_SUCCESS, ret);
243 }
244 
245 
246 /**
247   * @tc.name: SetGnssReferenceInfo0100
248   * @tc.desc: Inject reference information to the GNSS module.
249   * @tc.type: FUNC
250   */
251 HWTEST_F(LocationGnssTest, SUB_DriverSystem_SetGnssReferenceInfo_0100, TestSize.Level1)
252 {
253     if (g_ignssHci == nullptr) {
254         ASSERT_NE(nullptr, g_ignssHci);
255         return;
256     }
257     GnssRefInfo refInfo;
258     refInfo.type = GnssRefInfoType::GNSS_REF_INFO_TIME;
259     refInfo.time.timeMs = 50;
260     refInfo.time.timeReferenceMs = 100;
261     refInfo.time.uncertainty = 200;
262     refInfo.location.latitude = 39.56;
263     refInfo.location.longitude = 116.20;
264     refInfo.location.accuracy = 90;
265     refInfo.best_location.latitude = 39.58;
266     refInfo.best_location.longitude = 116.45;
267     refInfo.best_location.altitude = 110;
268     refInfo.best_location.accuracy = 60;
269     refInfo.best_location.speed = 60;
270     refInfo.best_location.direction = 60;
271     refInfo.best_location.timeStamp = 60;
272     refInfo.best_location.timeSinceBoot = 60;
273     int32_t ret = g_ignssHci->SetGnssReferenceInfo(refInfo);
274     EXPECT_EQ(HDF_SUCCESS, ret);
275 }
276 
277 /**
278   * @tc.name: StopGnss0100
279   * @tc.desc: Stop the navigation function in normal mode.
280   * @tc.type: FUNC
281   */
282 HWTEST_F(LocationGnssTest, SUB_DriverSystem_StopGnss_0100, TestSize.Level1)
283 {
284     if (g_ignssHci == nullptr) {
285         ASSERT_NE(nullptr, g_ignssHci);
286         return;
287     }
288     GnssStartType stoptype = GnssStartType::GNSS_START_TYPE_NORMAL;
289     int32_t ret = g_ignssHci->StopGnss(stoptype);
290     EXPECT_EQ(HDF_SUCCESS, ret);
291 }
292 
293 /**
294   * @tc.name: DeleteAuxiliaryData0100
295   * @tc.desc: Delete the specified auxiliary data.
296   * @tc.type: FUNC
297   */
298 HWTEST_F(LocationGnssTest, SUB_DriverSystem_DeleteAuxiliaryData_0100, TestSize.Level1)
299 {
300     if (g_ignssHci == nullptr) {
301         ASSERT_NE(nullptr, g_ignssHci);
302         return;
303     }
304     GnssAuxiliaryData auxdata = GnssAuxiliaryData::GNSS_AUXILIARY_DATA_EPHEMERIS;
305     int32_t ret = g_ignssHci->DeleteAuxiliaryData(auxdata);
306     EXPECT_EQ(HDF_SUCCESS, ret);
307 }
308 
309 
310 /**
311   * @tc.name: SetPredictGnssData0100
312   * @tc.desc: Ingesting Predict Gnss Data.
313   * @tc.type: FUNC
314   */
315 HWTEST_F(LocationGnssTest, SUB_DriverSystem_SetPredictGnssData_0100, TestSize.Level1)
316 {
317     if (g_ignssHci == nullptr) {
318         ASSERT_NE(nullptr, g_ignssHci);
319         return;
320     }
321     const std::string str1 = "testing";
322     int32_t ret = g_ignssHci->SetPredictGnssData(str1);
323     EXPECT_EQ(HDF_SUCCESS, ret);
324 }
325 
326 /**
327   * @tc.name: GetCachedGnssLocationsSize0100
328   * @tc.desc: Obtain the number of locations that can be cached by the GNSS module.
329   * @tc.type: FUNC
330   */
331 HWTEST_F(LocationGnssTest, SUB_DriverSystem_GetCachedGnssLocationsSize_0100, TestSize.Level1)
332 {
333     if (g_ignssHci == nullptr) {
334         ASSERT_NE(nullptr, g_ignssHci);
335         return;
336     }
337     int cach_size = 60;
338     int32_t ret = g_ignssHci->GetCachedGnssLocationsSize(cach_size);
339     EXPECT_EQ(HDF_SUCCESS, ret);
340 }
341 
342 /**
343   * @tc.name: GetCachedGnssLocations0100
344   * @tc.desc: Request to obtain all the location information in the GNSS cache at a time and clear the cache buffer.
345   * @tc.type: FUNC
346   */
347 HWTEST_F(LocationGnssTest, SUB_DriverSystem_GetCachedGnssLocations_0100, TestSize.Level1)
348 {
349     if (g_ignssHci == nullptr) {
350         ASSERT_NE(nullptr, g_ignssHci);
351         return;
352     }
353     int32_t ret = g_ignssHci->GetCachedGnssLocations();
354     EXPECT_EQ(HDF_SUCCESS, ret);
355 }
356 
357 /**
358   * @tc.name: DisableGnss0100
359   * @tc.desc: Disable the GNSS module.
360   * @tc.type: FUNC
361   */
362 HWTEST_F(LocationGnssTest, SUB_DriverSystem_DisableGnss_0100, TestSize.Level1)
363 {
364     if (g_ignssHci == nullptr) {
365         ASSERT_NE(nullptr, g_ignssHci);
366         return;
367     }
368     int32_t ret = g_ignssHci->DisableGnss();
369     EXPECT_EQ(HDF_SUCCESS, ret);
370 }
371