17c804472Sopenharmony_ci/*
27c804472Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
37c804472Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47c804472Sopenharmony_ci * you may not use this file except in compliance with the License.
57c804472Sopenharmony_ci * You may obtain a copy of the License at
67c804472Sopenharmony_ci *
77c804472Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87c804472Sopenharmony_ci *
97c804472Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107c804472Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117c804472Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127c804472Sopenharmony_ci * See the License for the specific language governing permissions and
137c804472Sopenharmony_ci * limitations under the License.
147c804472Sopenharmony_ci */
157c804472Sopenharmony_ci
167c804472Sopenharmony_ci#include "gtest/gtest.h"
177c804472Sopenharmony_ci#include "location.h"
187c804472Sopenharmony_ci#include "SharedData.h"
197c804472Sopenharmony_ci#define private public
207c804472Sopenharmony_ci#include "VirtualLocation.h"
217c804472Sopenharmony_ci
227c804472Sopenharmony_cinamespace {
237c804472Sopenharmony_ci    struct LocSuccessData {
247c804472Sopenharmony_ci        LocationData data;
257c804472Sopenharmony_ci    };
267c804472Sopenharmony_ci
277c804472Sopenharmony_ci    TEST(GeoLocationTest, GetGeoLocationTypeTest)
287c804472Sopenharmony_ci    {
297c804472Sopenharmony_ci        EXPECT_EQ(std::string(GetGeoLocationType()), "gps");
307c804472Sopenharmony_ci    }
317c804472Sopenharmony_ci
327c804472Sopenharmony_ci    TEST(GeoLocationTest, GetSupportedGeoCoordTypesTest)
337c804472Sopenharmony_ci    {
347c804472Sopenharmony_ci        EXPECT_EQ(std::string(GetSupportedGeoCoordTypes()), "wgs84");
357c804472Sopenharmony_ci    }
367c804472Sopenharmony_ci
377c804472Sopenharmony_ci    void LocDataUpdateCallback(const int8_t *data, uint32_t len)
387c804472Sopenharmony_ci    {
397c804472Sopenharmony_ci        (void)data;
407c804472Sopenharmony_ci        (void)len;
417c804472Sopenharmony_ci    }
427c804472Sopenharmony_ci
437c804472Sopenharmony_ci    TEST(GeoLocationTest, GetGeoLocationTest)
447c804472Sopenharmony_ci    {
457c804472Sopenharmony_ci        int32_t ret = GetGeoLocation(nullptr, nullptr, nullptr, 0);
467c804472Sopenharmony_ci        EXPECT_EQ(ret, -1); // -1 is expect return value
477c804472Sopenharmony_ci        int32_t ret1 = GetGeoLocation(LocDataUpdateCallback, nullptr, nullptr, 0);
487c804472Sopenharmony_ci        EXPECT_EQ(ret1, 0); // 0 is expect return value
497c804472Sopenharmony_ci    }
507c804472Sopenharmony_ci
517c804472Sopenharmony_ci    TEST(GeoLocationTest, SubGeoLocationTest)
527c804472Sopenharmony_ci    {
537c804472Sopenharmony_ci        int32_t ret = SubGeoLocation(LocDataUpdateCallback);
547c804472Sopenharmony_ci        EXPECT_EQ(ret, 0); // 0 is expect return value
557c804472Sopenharmony_ci    }
567c804472Sopenharmony_ci
577c804472Sopenharmony_ci    TEST(GeoLocationTest, UnSubGeoLocationTest)
587c804472Sopenharmony_ci    {
597c804472Sopenharmony_ci        UnSubGeoLocation(LocDataUpdateCallback);
607c804472Sopenharmony_ci        EXPECT_FALSE(VirtualLocation::GetInstance().isSubsribe);
617c804472Sopenharmony_ci    }
627c804472Sopenharmony_ci
637c804472Sopenharmony_ci    TEST(GeoLocationTest, DestroyGeoLocationTest)
647c804472Sopenharmony_ci    {
657c804472Sopenharmony_ci        DestroyGeoLocation(LocDataUpdateCallback);
667c804472Sopenharmony_ci        EXPECT_FALSE(VirtualLocation::GetInstance().isSubsribe);
677c804472Sopenharmony_ci    }
687c804472Sopenharmony_ci
697c804472Sopenharmony_ci    TEST(GeoLocationTest, SerializeLocDataTest)
707c804472Sopenharmony_ci    {
717c804472Sopenharmony_ci        int32_t ret = SerializeLocData(nullptr, 0, nullptr);
727c804472Sopenharmony_ci        EXPECT_EQ(ret, -1); // -1 is expect return value
737c804472Sopenharmony_ci        ret = SerializeLocData(VirtualLocation::GetInstance().GetMockPointer(), 0, nullptr);
747c804472Sopenharmony_ci        EXPECT_EQ(ret, -1); // -1 is expect return value
757c804472Sopenharmony_ci        uint32_t len = 1;
767c804472Sopenharmony_ci        ret = SerializeLocData(VirtualLocation::GetInstance().GetMockPointer(), len, nullptr);
777c804472Sopenharmony_ci        EXPECT_EQ(ret, -1); // -1 is expect return value
787c804472Sopenharmony_ci        LocationData rspData;
797c804472Sopenharmony_ci        ret = SerializeLocData(VirtualLocation::GetInstance().GetMockPointer(), len, &rspData);
807c804472Sopenharmony_ci        EXPECT_EQ(ret, 0); // 0 is expect return value
817c804472Sopenharmony_ci    }
827c804472Sopenharmony_ci}