19762338dSopenharmony_ci/*
29762338dSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
39762338dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
49762338dSopenharmony_ci * you may not use this file except in compliance with the License.
59762338dSopenharmony_ci * You may obtain a copy of the License at
69762338dSopenharmony_ci *
79762338dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
89762338dSopenharmony_ci *
99762338dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
109762338dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
119762338dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129762338dSopenharmony_ci * See the License for the specific language governing permissions and
139762338dSopenharmony_ci * limitations under the License.
149762338dSopenharmony_ci */
159762338dSopenharmony_ci
169762338dSopenharmony_ci#include "idevmgr_hdi.h"
179762338dSopenharmony_ci#include <iostream>
189762338dSopenharmony_ci#include <cmath>
199762338dSopenharmony_ci#include <cstdio>
209762338dSopenharmony_ci#include <unistd.h>
219762338dSopenharmony_ci#include <gtest/gtest.h>
229762338dSopenharmony_ci#include <securec.h>
239762338dSopenharmony_ci#ifdef FEATURE_GNSS_SUPPORT
249762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
259762338dSopenharmony_ci#include <osal_mem.h>
269762338dSopenharmony_ci#include "osal_time.h"
279762338dSopenharmony_ci#include "hdf_base.h"
289762338dSopenharmony_ci#include "hdf_log.h"
299762338dSopenharmony_ci#include "hdf_sbuf.h"
309762338dSopenharmony_ci#include "v2_0/ia_gnss_interface.h"
319762338dSopenharmony_ci#include "v2_0/ignss_interface.h"
329762338dSopenharmony_ci#include "agnss_callback_impl.h"
339762338dSopenharmony_ci#include "cellular_data_client.h"
349762338dSopenharmony_ci#include "gnss_callback_impl.h"
359762338dSopenharmony_ci#endif
369762338dSopenharmony_ci#endif
379762338dSopenharmony_ci
389762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
399762338dSopenharmony_ciusing namespace OHOS::HDI::Location::Agnss::V2_0;
409762338dSopenharmony_ciusing namespace OHOS::HDI::Location::Gnss::V2_0;
419762338dSopenharmony_ci#endif
429762338dSopenharmony_ciusing namespace std;
439762338dSopenharmony_ciusing namespace testing::ext;
449762338dSopenharmony_ci
459762338dSopenharmony_cinamespace {
469762338dSopenharmony_ci    #ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
479762338dSopenharmony_ci    using OHOS::Telephony::CellInformation;
489762338dSopenharmony_ci    sptr<IAGnssInterface> g_iagnssHci = nullptr;
499762338dSopenharmony_ci    sptr<IGnssInterface> g_ignssHci = nullptr;
509762338dSopenharmony_ci    constexpr const char *AGNSS_SERVICE_NAME = "agnss_interface_service";
519762338dSopenharmony_ci    constexpr const char *GNSS_SERVICE_NAME = "gnss_interface_service";
529762338dSopenharmony_ci    constexpr const char *GEOFENCE_SERVICE_NAME = "geofence_interface_service";
539762338dSopenharmony_ci    const char DEFAULT_STRING[] = "error";
549762338dSopenharmony_ci    const std::wstring DEFAULT_WSTRING = L"error";
559762338dSopenharmony_ci    const std::u16string DEFAULT_USTRING = u"error";
569762338dSopenharmony_ci    #endif
579762338dSopenharmony_ci}
589762338dSopenharmony_ci
599762338dSopenharmony_ciclass LocationAgnssTest : public testing::Test {
609762338dSopenharmony_cipublic:
619762338dSopenharmony_ci    static void SetUpTestCase();
629762338dSopenharmony_ci    static void TearDownTestCase();
639762338dSopenharmony_ci    void SetUp();
649762338dSopenharmony_ci    void TearDown();
659762338dSopenharmony_ci};
669762338dSopenharmony_ci
679762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
689762338dSopenharmony_ciint32_t AgnssCallbackImpl::RequestSetUpAgnssDataLink(const AGnssDataLinkRequest& request)
699762338dSopenharmony_ci{
709762338dSopenharmony_ci    printf("AGnssEventCallback::RequestSetUpAgnssDataLink. agnsstype:%d, setUpType:%d\n",
719762338dSopenharmony_ci        static_cast<int>(request.agnssType), static_cast<int>(request.setUpType));
729762338dSopenharmony_ci    return HDF_SUCCESS;
739762338dSopenharmony_ci}
749762338dSopenharmony_ci
759762338dSopenharmony_ciint32_t AgnssCallbackImpl::RequestSubscriberSetId(SubscriberSetIdType type)
769762338dSopenharmony_ci{
779762338dSopenharmony_ci    printf("AGnssEventCallback::RequestSubscriberSetId. type:%d\n", static_cast<int>(type));
789762338dSopenharmony_ci    int slotId = Telephony::CellularDataClient::GetInstance().GetDefaultCellularDataSlotId();
799762338dSopenharmony_ci    std::u16string imsi;
809762338dSopenharmony_ci    DelayedRefSingleton<Telephony::CoreServiceClient>::GetInstance().GetIMSI(slotId, imsi);
819762338dSopenharmony_ci    SubscriberSetId setId;
829762338dSopenharmony_ci    setId.type = HDI::Location::Agnss::V2_0::AGNSS_SETID_TYPE_IMSI;
839762338dSopenharmony_ci    setId.id = Str16ToStr8(imsi);
849762338dSopenharmony_ci    if (g_iagnssHci == nullptr) {
859762338dSopenharmony_ci        printf("g_iagnssHci is null!\n");
869762338dSopenharmony_ci        return HDF_FAILURE;
879762338dSopenharmony_ci    }
889762338dSopenharmony_ci    g_iagnssHci->SetSubscriberSetId(setId);
899762338dSopenharmony_ci    return HDF_SUCCESS;
909762338dSopenharmony_ci}
919762338dSopenharmony_ci
929762338dSopenharmony_ciint32_t AgnssCallbackImpl::RequestAgnssRefInfo(AGnssRefInfoType type)
939762338dSopenharmony_ci{
949762338dSopenharmony_ci    if (g_iagnssHci == nullptr) {
959762338dSopenharmony_ci        printf("g_iagnssHci is null!\n");
969762338dSopenharmony_ci        return HDF_FAILURE;
979762338dSopenharmony_ci    }
989762338dSopenharmony_ci    int slotId = Telephony::CellularDataClient::GetInstance().GetDefaultCellularDataSlotId();
999762338dSopenharmony_ci    std::vector<sptr<CellInformation>> cellInformations;
1009762338dSopenharmony_ci    DelayedRefSingleton<Telephony::CoreServiceClient>::GetInstance().GetCellInfoList(slotId, cellInformations);
1019762338dSopenharmony_ci    printf("RequestAgnssRefInfo,cellInformations.\n");
1029762338dSopenharmony_ci    for (sptr<CellInformation> infoItem : cellInformations) {
1039762338dSopenharmony_ci        if (!infoItem->GetIsCamped()) {
1049762338dSopenharmony_ci            printf("GetIsCamped return false\n");
1059762338dSopenharmony_ci            continue;
1069762338dSopenharmony_ci        }
1079762338dSopenharmony_ci        AGnssRefInfo refInfo;
1089762338dSopenharmony_ci        CellInformation::CellType cellType = infoItem->GetNetworkType();
1099762338dSopenharmony_ci        refInfo.type = type;
1109762338dSopenharmony_ci        switch (cellType) {
1119762338dSopenharmony_ci            case CellInformation::CellType::CELL_TYPE_GSM: {
1129762338dSopenharmony_ci                JudgmentDataGsm(refInfo, infoItem);
1139762338dSopenharmony_ci                break;
1149762338dSopenharmony_ci            }
1159762338dSopenharmony_ci            case CellInformation::CellType::CELL_TYPE_LTE: {
1169762338dSopenharmony_ci                JudgmentDataLte(refInfo, infoItem);
1179762338dSopenharmony_ci                break;
1189762338dSopenharmony_ci            }
1199762338dSopenharmony_ci            case CellInformation::CellType::CELL_TYPE_CDMA:
1209762338dSopenharmony_ci            case CellInformation::CellType::CELL_TYPE_WCDMA:
1219762338dSopenharmony_ci            case CellInformation::CellType::CELL_TYPE_TDSCDMA: {
1229762338dSopenharmony_ci                JudgmentDataUmts(refInfo, infoItem);
1239762338dSopenharmony_ci                break;
1249762338dSopenharmony_ci            }
1259762338dSopenharmony_ci            case CellInformation::CellType::CELL_TYPE_NR: {
1269762338dSopenharmony_ci                JudgmentDataNr(refInfo, infoItem);
1279762338dSopenharmony_ci                break;
1289762338dSopenharmony_ci            }
1299762338dSopenharmony_ci            default:
1309762338dSopenharmony_ci                break;
1319762338dSopenharmony_ci        }
1329762338dSopenharmony_ci        g_iagnssHci->SetAgnssRefInfo(refInfo);
1339762338dSopenharmony_ci        break;
1349762338dSopenharmony_ci    }
1359762338dSopenharmony_ci    return HDF_SUCCESS;
1369762338dSopenharmony_ci}
1379762338dSopenharmony_ci
1389762338dSopenharmony_civoid AgnssCallbackImpl::JudgmentDataGsm(AGnssRefInfo& refInfo, sptr<CellInformation> infoItem)
1399762338dSopenharmony_ci{
1409762338dSopenharmony_ci    auto gsmCellInfo = static_cast<Telephony::GsmCellInformation *>(infoItem.GetRefPtr());
1419762338dSopenharmony_ci    if (gsmCellInfo != nullptr) {
1429762338dSopenharmony_ci        refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_GSM;
1439762338dSopenharmony_ci        refInfo.cellId.mcc = static_cast<unsigned short>(std::stoi(gsmCellInfo->GetMcc()));
1449762338dSopenharmony_ci        refInfo.cellId.mnc = static_cast<unsigned short>(std::stoi(gsmCellInfo->GetMnc()));
1459762338dSopenharmony_ci        refInfo.cellId.lac = static_cast<unsigned short>(gsmCellInfo->GetLac());
1469762338dSopenharmony_ci        refInfo.cellId.cid = static_cast<unsigned int>(gsmCellInfo->GetCellId());
1479762338dSopenharmony_ci    }
1489762338dSopenharmony_ci}
1499762338dSopenharmony_ci
1509762338dSopenharmony_civoid AgnssCallbackImpl::JudgmentDataLte(AGnssRefInfo& refInfo, sptr<CellInformation> infoItem)
1519762338dSopenharmony_ci{
1529762338dSopenharmony_ci    auto lteCellInfo = static_cast<Telephony::LteCellInformation *>(infoItem.GetRefPtr());
1539762338dSopenharmony_ci    if (lteCellInfo != nullptr) {
1549762338dSopenharmony_ci        refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_LTE;
1559762338dSopenharmony_ci        refInfo.cellId.mcc = static_cast<unsigned short>(std::stoi(lteCellInfo->GetMcc()));
1569762338dSopenharmony_ci        refInfo.cellId.mnc = static_cast<unsigned short>(std::stoi(lteCellInfo->GetMnc()));
1579762338dSopenharmony_ci        refInfo.cellId.tac = static_cast<unsigned short>(lteCellInfo->GetTac());
1589762338dSopenharmony_ci        refInfo.cellId.cid = static_cast<unsigned int>(lteCellInfo->GetCellId());
1599762338dSopenharmony_ci        refInfo.cellId.pcid = static_cast<unsigned short>(lteCellInfo->GetPci());
1609762338dSopenharmony_ci    }
1619762338dSopenharmony_ci}
1629762338dSopenharmony_ci
1639762338dSopenharmony_civoid AgnssCallbackImpl::JudgmentDataNr(AGnssRefInfo& refInfo, sptr<CellInformation> infoItem)
1649762338dSopenharmony_ci{
1659762338dSopenharmony_ci    auto nrCellInfo = static_cast<Telephony::NrCellInformation *>(infoItem.GetRefPtr());
1669762338dSopenharmony_ci    if (nrCellInfo != nullptr) {
1679762338dSopenharmony_ci        refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_NR;
1689762338dSopenharmony_ci        refInfo.cellId.mcc = static_cast<unsigned short>(std::stoi(nrCellInfo->GetMcc()));
1699762338dSopenharmony_ci        refInfo.cellId.mnc = static_cast<unsigned short>(std::stoi(nrCellInfo->GetMnc()));
1709762338dSopenharmony_ci        refInfo.cellId.tac = static_cast<unsigned short>(nrCellInfo->GetTac());
1719762338dSopenharmony_ci        refInfo.cellId.cid = static_cast<unsigned int>(nrCellInfo->GetCellId());
1729762338dSopenharmony_ci        refInfo.cellId.pcid = static_cast<unsigned short>(nrCellInfo->GetPci());
1739762338dSopenharmony_ci        refInfo.cellId.nci = static_cast<unsigned int>(nrCellInfo->GetNci());
1749762338dSopenharmony_ci    }
1759762338dSopenharmony_ci}
1769762338dSopenharmony_ci
1779762338dSopenharmony_civoid AgnssCallbackImpl::JudgmentDataUmts(AGnssRefInfo& refInfo, sptr<CellInformation> infoItem)
1789762338dSopenharmony_ci{
1799762338dSopenharmony_ci    auto wcdmaCellInfo = static_cast<Telephony::WcdmaCellInformation *>(infoItem.GetRefPtr());
1809762338dSopenharmony_ci    if (wcdmaCellInfo != nullptr) {
1819762338dSopenharmony_ci        refInfo.cellId.type = HDI::Location::Agnss::V2_0::CELLID_TYPE_UMTS;
1829762338dSopenharmony_ci        refInfo.cellId.mcc = static_cast<unsigned short>(std::stoi(wcdmaCellInfo->GetMcc()));
1839762338dSopenharmony_ci        refInfo.cellId.mnc = static_cast<unsigned short>(std::stoi(wcdmaCellInfo->GetMnc()));
1849762338dSopenharmony_ci        refInfo.cellId.lac = static_cast<unsigned short>(wcdmaCellInfo->GetLac());
1859762338dSopenharmony_ci        refInfo.cellId.cid = static_cast<unsigned int>(wcdmaCellInfo->GetCellId());
1869762338dSopenharmony_ci    }
1879762338dSopenharmony_ci}
1889762338dSopenharmony_ci
1899762338dSopenharmony_cistd::string AgnssCallbackImpl::Str16ToStr8(std::u16string str)
1909762338dSopenharmony_ci{
1919762338dSopenharmony_ci    if (str == DEFAULT_USTRING) {
1929762338dSopenharmony_ci        return DEFAULT_STRING;
1939762338dSopenharmony_ci    }
1949762338dSopenharmony_ci    std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert(DEFAULT_STRING);
1959762338dSopenharmony_ci    std::string result = convert.to_bytes(str);
1969762338dSopenharmony_ci    return result == DEFAULT_STRING ? "" : result;
1979762338dSopenharmony_ci}
1989762338dSopenharmony_ci
1999762338dSopenharmony_ciint32_t GnssCallbackImpl::ReportLocation(const LocationInfo& location)
2009762338dSopenharmony_ci{
2019762338dSopenharmony_ci    if (location.timeSinceBoot != 0) {
2029762338dSopenharmony_ci        printf("Location success!!\n");
2039762338dSopenharmony_ci        return HDF_SUCCESS;
2049762338dSopenharmony_ci    }
2059762338dSopenharmony_ci    else{
2069762338dSopenharmony_ci        printf("Location fail!!\n");
2079762338dSopenharmony_ci        return HDF_FAILURE;
2089762338dSopenharmony_ci    }
2099762338dSopenharmony_ci}
2109762338dSopenharmony_ci
2119762338dSopenharmony_ciint32_t GnssCallbackImpl::ReportGnssWorkingStatus(GnssWorkingStatus status)
2129762338dSopenharmony_ci{
2139762338dSopenharmony_ci    if (status == GnssWorkingStatus::GNSS_WORKING_STATUS_NONE) {
2149762338dSopenharmony_ci        printf("GNSS_WORKING_STATUS_NONE\n");
2159762338dSopenharmony_ci        return HDF_SUCCESS;
2169762338dSopenharmony_ci    } else if (status == GnssWorkingStatus::GNSS_WORKING_STATUS_SESSION_BEGIN) {
2179762338dSopenharmony_ci        printf("GNSS_WORKING_STATUS_SESSION_BEGIN\n");
2189762338dSopenharmony_ci        return HDF_SUCCESS;
2199762338dSopenharmony_ci    } else if (status == GnssWorkingStatus::GNSS_WORKING_STATUS_SESSION_END) {
2209762338dSopenharmony_ci        printf("GNSS_WORKING_STATUS_SESSION_END\n");
2219762338dSopenharmony_ci        return HDF_SUCCESS;
2229762338dSopenharmony_ci    } else if (status == GnssWorkingStatus::GNSS_WORKING_STATUS_ENGINE_ON) {
2239762338dSopenharmony_ci        printf("GNSS_WORKING_STATUS_ENGINE_ON\n");
2249762338dSopenharmony_ci        return HDF_SUCCESS;
2259762338dSopenharmony_ci    } else if (status == GnssWorkingStatus::GNSS_WORKING_STATUS_ENGINE_OFF) {
2269762338dSopenharmony_ci        printf("GNSS_WORKING_STATUS_ENGINE_OFF\n");
2279762338dSopenharmony_ci        return HDF_SUCCESS;
2289762338dSopenharmony_ci    } else {
2299762338dSopenharmony_ci        printf("Gnss status fail\n");
2309762338dSopenharmony_ci        return HDF_FAILURE;
2319762338dSopenharmony_ci    }
2329762338dSopenharmony_ci}
2339762338dSopenharmony_ci
2349762338dSopenharmony_ciint32_t GnssCallbackImpl::ReportNmea(int64_t timestamp, const std::string& nmea, int32_t length)
2359762338dSopenharmony_ci{
2369762338dSopenharmony_ci    (void)nmea;
2379762338dSopenharmony_ci    (void)timestamp;
2389762338dSopenharmony_ci    if (length >= 0) {
2399762338dSopenharmony_ci        printf("Report nmea success\n");
2409762338dSopenharmony_ci        return HDF_SUCCESS;
2419762338dSopenharmony_ci    }
2429762338dSopenharmony_ci    else{
2439762338dSopenharmony_ci        printf("Report nmea fail\n");
2449762338dSopenharmony_ci        return HDF_FAILURE;
2459762338dSopenharmony_ci    }
2469762338dSopenharmony_ci}
2479762338dSopenharmony_ci
2489762338dSopenharmony_ciint32_t GnssCallbackImpl::ReportGnssCapabilities(unsigned int capabilities)
2499762338dSopenharmony_ci{
2509762338dSopenharmony_ci    (void)capabilities;
2519762338dSopenharmony_ci    return HDF_SUCCESS;
2529762338dSopenharmony_ci}
2539762338dSopenharmony_ci
2549762338dSopenharmony_ciint32_t GnssCallbackImpl::ReportSatelliteStatusInfo(const SatelliteStatusInfo& info)
2559762338dSopenharmony_ci{
2569762338dSopenharmony_ci    if (info.satellitesNumber <= 0) {
2579762338dSopenharmony_ci        printf("SvStatusCallback, satellites_num <= 0!\n");
2589762338dSopenharmony_ci        return HDF_ERR_INVALID_PARAM;
2599762338dSopenharmony_ci    }
2609762338dSopenharmony_ci    if (((info.carrierFrequencies).size()) > 0) {
2619762338dSopenharmony_ci        printf("Get satellite info success!!\n");
2629762338dSopenharmony_ci        return HDF_SUCCESS;
2639762338dSopenharmony_ci    }
2649762338dSopenharmony_ci    else{
2659762338dSopenharmony_ci        printf("Get satellite info fail!!\n");
2669762338dSopenharmony_ci        return HDF_FAILURE;
2679762338dSopenharmony_ci    }
2689762338dSopenharmony_ci}
2699762338dSopenharmony_ci
2709762338dSopenharmony_ciint32_t GnssCallbackImpl::RequestGnssReferenceInfo(GnssRefInfoType type)
2719762338dSopenharmony_ci{
2729762338dSopenharmony_ci    (void)type;
2739762338dSopenharmony_ci    return HDF_SUCCESS;
2749762338dSopenharmony_ci}
2759762338dSopenharmony_ci
2769762338dSopenharmony_ciint32_t GnssCallbackImpl::RequestPredictGnssData()
2779762338dSopenharmony_ci{
2789762338dSopenharmony_ci    return HDF_SUCCESS;
2799762338dSopenharmony_ci}
2809762338dSopenharmony_ci
2819762338dSopenharmony_ciint32_t GnssCallbackImpl::ReportCachedLocation(const std::vector<LocationInfo>& gnssLocations)
2829762338dSopenharmony_ci{
2839762338dSopenharmony_ci    (void)gnssLocations;
2849762338dSopenharmony_ci    return HDF_SUCCESS;
2859762338dSopenharmony_ci}
2869762338dSopenharmony_ci
2879762338dSopenharmony_ciint32_t GnssCallbackImpl::ReportGnssNiNotification(const GnssNiNotificationRequest& notification)
2889762338dSopenharmony_ci{
2899762338dSopenharmony_ci    (void)notification;
2909762338dSopenharmony_ci    return HDF_SUCCESS;
2919762338dSopenharmony_ci}
2929762338dSopenharmony_ci#endif
2939762338dSopenharmony_ci
2949762338dSopenharmony_civoid LocationAgnssTest::SetUpTestCase()
2959762338dSopenharmony_ci{
2969762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
2979762338dSopenharmony_ci    auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get();
2989762338dSopenharmony_ci    if (devmgr == nullptr) {
2999762338dSopenharmony_ci        printf("fail to get devmgr.\n");
3009762338dSopenharmony_ci        return;
3019762338dSopenharmony_ci    }
3029762338dSopenharmony_ci    if (devmgr->LoadDevice(GNSS_SERVICE_NAME) != 0) {
3039762338dSopenharmony_ci        printf("Load gnss service failed!\n");
3049762338dSopenharmony_ci        return;
3059762338dSopenharmony_ci    }
3069762338dSopenharmony_ci    if (devmgr->LoadDevice(AGNSS_SERVICE_NAME) != 0) {
3079762338dSopenharmony_ci        printf("Load agnss service failed!\n");
3089762338dSopenharmony_ci        return;
3099762338dSopenharmony_ci    }
3109762338dSopenharmony_ci    if (devmgr->LoadDevice(GEOFENCE_SERVICE_NAME) != 0) {
3119762338dSopenharmony_ci        printf("Load geofence service failed!\n");
3129762338dSopenharmony_ci        return;
3139762338dSopenharmony_ci    }
3149762338dSopenharmony_ci    g_iagnssHci = IAGnssInterface::Get();
3159762338dSopenharmony_ci    g_ignssHci = IGnssInterface::Get();
3169762338dSopenharmony_ci    sptr<IGnssCallback> gnss_callback = new (std::nothrow) GnssCallbackImpl();
3179762338dSopenharmony_ci    if (gnss_callback == nullptr) {
3189762338dSopenharmony_ci        ASSERT_NE(nullptr, gnss_callback);
3199762338dSopenharmony_ci        return;
3209762338dSopenharmony_ci    }
3219762338dSopenharmony_ci    g_ignssHci->EnableGnss(gnss_callback);
3229762338dSopenharmony_ci#endif
3239762338dSopenharmony_ci}
3249762338dSopenharmony_ci
3259762338dSopenharmony_civoid LocationAgnssTest::TearDownTestCase()
3269762338dSopenharmony_ci{
3279762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
3289762338dSopenharmony_ci    auto devmgr = HDI::DeviceManager::V1_0::IDeviceManager::Get();
3299762338dSopenharmony_ci    if (devmgr == nullptr) {
3309762338dSopenharmony_ci        printf("fail to get devmgr.\n");
3319762338dSopenharmony_ci        return;
3329762338dSopenharmony_ci    }
3339762338dSopenharmony_ci    if (devmgr->UnloadDevice(GNSS_SERVICE_NAME) != 0) {
3349762338dSopenharmony_ci        printf("Load gnss service failed!\n");
3359762338dSopenharmony_ci        return;
3369762338dSopenharmony_ci    }
3379762338dSopenharmony_ci    if (devmgr->UnloadDevice(AGNSS_SERVICE_NAME) != 0) {
3389762338dSopenharmony_ci        printf("Load agnss service failed!\n");
3399762338dSopenharmony_ci        return;
3409762338dSopenharmony_ci    }
3419762338dSopenharmony_ci    if (devmgr->UnloadDevice(GEOFENCE_SERVICE_NAME) != 0) {
3429762338dSopenharmony_ci        printf("Load geofence service failed!\n");
3439762338dSopenharmony_ci        return;
3449762338dSopenharmony_ci    }
3459762338dSopenharmony_ci    g_ignssHci->DisableGnss();
3469762338dSopenharmony_ci#endif
3479762338dSopenharmony_ci}
3489762338dSopenharmony_ci
3499762338dSopenharmony_civoid LocationAgnssTest::SetUp()
3509762338dSopenharmony_ci{
3519762338dSopenharmony_ci}
3529762338dSopenharmony_ci
3539762338dSopenharmony_civoid LocationAgnssTest::TearDown()
3549762338dSopenharmony_ci{
3559762338dSopenharmony_ci}
3569762338dSopenharmony_ci
3579762338dSopenharmony_ci
3589762338dSopenharmony_ci/**
3599762338dSopenharmony_ci  * @tc.name: SetAgnssServer0001
3609762338dSopenharmony_ci  * @tc.desc: Set the Agnss Server Information.
3619762338dSopenharmony_ci  * @tc.type: FUNC
3629762338dSopenharmony_ci  */
3639762338dSopenharmony_ciHWTEST_F(LocationAgnssTest, SUB_DriverSystem_SetAgnssServer_0100, TestSize.Level1)
3649762338dSopenharmony_ci{
3659762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
3669762338dSopenharmony_ci    if (g_iagnssHci == nullptr) {
3679762338dSopenharmony_ci        ASSERT_NE(nullptr, g_iagnssHci);
3689762338dSopenharmony_ci        return;
3699762338dSopenharmony_ci    }
3709762338dSopenharmony_ci    AGnssServerInfo server;
3719762338dSopenharmony_ci    server.type = AGnssUserPlaneProtocol::AGNSS_TYPE_SUPL;
3729762338dSopenharmony_ci    server.server = "test";
3739762338dSopenharmony_ci    server.port = 80001;
3749762338dSopenharmony_ci    int32_t ret = g_iagnssHci->SetAgnssServer(server);
3759762338dSopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, ret);
3769762338dSopenharmony_ci#endif
3779762338dSopenharmony_ci}
3789762338dSopenharmony_ci
3799762338dSopenharmony_ci/**
3809762338dSopenharmony_ci  * @tc.name: SetSubscriberSetId0001
3819762338dSopenharmony_ci  * @tc.desc: Set Subscriber Identity.
3829762338dSopenharmony_ci  * @tc.type: FUNC
3839762338dSopenharmony_ci  */
3849762338dSopenharmony_ciHWTEST_F(LocationAgnssTest, SUB_DriverSystem_SetSubscriberSetId_0100, TestSize.Level1)
3859762338dSopenharmony_ci{
3869762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
3879762338dSopenharmony_ci    if (g_iagnssHci == nullptr) {
3889762338dSopenharmony_ci        ASSERT_NE(nullptr, g_iagnssHci);
3899762338dSopenharmony_ci        return;
3909762338dSopenharmony_ci    }
3919762338dSopenharmony_ci    SubscriberSetId id;
3929762338dSopenharmony_ci    id.type = SubscriberSetIdType::AGNSS_SETID_TYPE_NULL;
3939762338dSopenharmony_ci    id.id = "111";
3949762338dSopenharmony_ci    int32_t ret = g_iagnssHci->SetSubscriberSetId(id);
3959762338dSopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, ret);
3969762338dSopenharmony_ci#endif
3979762338dSopenharmony_ci}
3989762338dSopenharmony_ci
3999762338dSopenharmony_ci/**
4009762338dSopenharmony_ci  * @tc.name: SetAgnssRefInfo0001
4019762338dSopenharmony_ci  * @tc.desc: Ingesting Reference Information.
4029762338dSopenharmony_ci  * @tc.type: FUNC
4039762338dSopenharmony_ci  */
4049762338dSopenharmony_ciHWTEST_F(LocationAgnssTest, SUB_DriverSystem_SetAgnssRefInfo_0100, TestSize.Level1)
4059762338dSopenharmony_ci{
4069762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
4079762338dSopenharmony_ci    if (g_iagnssHci == nullptr) {
4089762338dSopenharmony_ci        ASSERT_NE(nullptr, g_iagnssHci);
4099762338dSopenharmony_ci        return;
4109762338dSopenharmony_ci    }
4119762338dSopenharmony_ci    AGnssRefInfo refInfo;
4129762338dSopenharmony_ci    refInfo.type = AGnssRefInfoType::ANSS_REF_INFO_TYPE_CELLID;
4139762338dSopenharmony_ci    refInfo.cellId.type = CellIdType::CELLID_TYPE_GSM;
4149762338dSopenharmony_ci    refInfo.cellId.mcc = 100;
4159762338dSopenharmony_ci    refInfo.cellId.mnc = 8;
4169762338dSopenharmony_ci    refInfo.cellId.lac = 20;
4179762338dSopenharmony_ci    refInfo.cellId.cid = 50;
4189762338dSopenharmony_ci    refInfo.cellId.tac = 60;
4199762338dSopenharmony_ci    refInfo.cellId.pcid = 80;
4209762338dSopenharmony_ci    refInfo.cellId.nci = 90;
4219762338dSopenharmony_ci    int32_t ret = g_iagnssHci->SetAgnssRefInfo(refInfo);
4229762338dSopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, ret);
4239762338dSopenharmony_ci#endif
4249762338dSopenharmony_ci}
4259762338dSopenharmony_ci
4269762338dSopenharmony_ci/**
4279762338dSopenharmony_ci  * @tc.name: SetAgnssCallback0001
4289762338dSopenharmony_ci  * @tc.desc: Set the agnss callback function.
4299762338dSopenharmony_ci  * @tc.type: FUNC
4309762338dSopenharmony_ci  */
4319762338dSopenharmony_ciHWTEST_F(LocationAgnssTest, SUB_DriverSystem_SetAgnssCallback_0100, TestSize.Level1)
4329762338dSopenharmony_ci{
4339762338dSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_AGNSS_ENABLE
4349762338dSopenharmony_ci    if (g_iagnssHci == nullptr) {
4359762338dSopenharmony_ci        ASSERT_NE(nullptr, g_iagnssHci);
4369762338dSopenharmony_ci        return;
4379762338dSopenharmony_ci    }
4389762338dSopenharmony_ci    sptr<IAGnssCallback> agnss_callback = new (std::nothrow) AgnssCallbackImpl();
4399762338dSopenharmony_ci    if (agnss_callback == nullptr) {
4409762338dSopenharmony_ci        ASSERT_NE(nullptr, agnss_callback);
4419762338dSopenharmony_ci        return;
4429762338dSopenharmony_ci    }
4439762338dSopenharmony_ci    int32_t ret = g_iagnssHci->SetAgnssCallback(agnss_callback);
4449762338dSopenharmony_ci    EXPECT_EQ(HDF_SUCCESS, ret);
4459762338dSopenharmony_ci#endif
4469762338dSopenharmony_ci}
447