* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "location_common_test.h"
#include "string_ex.h"
#define private public
#include "request.h"
#include "location.h"
#include "request_config.h"
#undef private
#include "message_parcel.h"
#include "ipc_skeleton.h"
#include "common_event_subscriber.h"
#include "common_event_manager.h"
#include "common_event_support.h"
#include "system_ability_definition.h"
#include "want.h"
#include "want_agent.h"
#include "app_identity.h"
#include "common_hisysevent.h"
#include "common_utils.h"
#include "country_code_manager.h"
#include "constant_definition.h"
#include "permission_status_change_cb.h"
#ifdef FEATURE_GEOCODE_SUPPORT
#include "geo_address.h"
#include "geocoding_mock_info.h"
#endif
#include "location_data_rdb_helper.h"
#include "location_data_rdb_manager.h"
#include "location_log.h"
#define private public
#include "location_data_rdb_observer.h"
#include "location_sa_load_manager.h"
#undef private
#include "locator_event_subscriber.h"
#include "request_config.h"
#ifdef FEATURE_GNSS_SUPPORT
#include "satellite_status.h"
#endif
#include "hook_utils.h"
#include "hookmgr.h"
#include "permission_manager.h"
#include "lbs_res_loader.h"
#include "location_log_event_ids.h"
using namespace testing::ext;
namespace OHOS {
namespace Location {
using Want = OHOS::AAFwk::Want;
#ifdef FEATURE_GEOCODE_SUPPORT
const double MOCK_LATITUDE = 99.0;
const double MOCK_LONGITUDE = 100.0;
#endif
const double VERIFY_LOCATION_LATITUDE = 12.0;
const double VERIFY_LOCATION_LONGITUDE = 13.0;
const double VERIFY_LOCATION_ALTITUDE = 14.0;
const double VERIFY_LOCATION_ACCURACY = 1000.0;
const double VERIFY_LOCATION_SPEED = 10.0;
const double VERIFY_LOCATION_DIRECTION = 90.0;
const double VERIFY_LOCATION_TIME = 1000000000;
const double VERIFY_LOCATION_TIMESINCEBOOT = 1000000000;
const int32_t UN_SAID = 999999;
const std::string UN_URI = "unknown_uri";
void LocationCommonTest::SetUp()
{
}
void LocationCommonTest::TearDown()
{
}
#ifdef FEATURE_GEOCODE_SUPPORT
void LocationCommonTest::SetGeoAddress(std::unique_ptr<GeoAddress>& geoAddress)
{
MessageParcel parcel;
parcel.WriteDouble(MOCK_LATITUDE);
parcel.WriteDouble(MOCK_LONGITUDE);
parcel.WriteString16(u"locale");
parcel.WriteString16(u"placeName");
parcel.WriteString16(u"countryCode");
parcel.WriteString16(u"countryName");
parcel.WriteString16(u"administrativeArea");
parcel.WriteString16(u"subAdministrativeArea");
parcel.WriteString16(u"locality");
parcel.WriteString16(u"subLocality");
parcel.WriteString16(u"roadName");
parcel.WriteString16(u"subRoadName");
parcel.WriteString16(u"premises");
parcel.WriteString16(u"postalCode");
parcel.WriteString16(u"phoneNumber");
parcel.WriteString16(u"addressUrl");
parcel.WriteInt32(1);
parcel.WriteInt32(0);
parcel.WriteString16(u"line");
parcel.WriteBool(true);
geoAddress->ReadFromParcel(parcel);
}
#endif
#ifdef FEATURE_GEOCODE_SUPPORT
void LocationCommonTest::VerifyGeoAddressReadFromParcel(std::unique_ptr<GeoAddress>& geoAddress)
{
EXPECT_EQ(MOCK_LATITUDE, geoAddress->latitude_);
EXPECT_EQ(MOCK_LONGITUDE, geoAddress->longitude_);
EXPECT_EQ("locale", geoAddress->locale_);
EXPECT_EQ("placeName", geoAddress->placeName_);
EXPECT_EQ("countryCode", geoAddress->countryCode_);
EXPECT_EQ("countryName", geoAddress->countryName_);
EXPECT_EQ("administrativeArea", geoAddress->administrativeArea_);
EXPECT_EQ("subAdministrativeArea", geoAddress->subAdministrativeArea_);
EXPECT_EQ("locality", geoAddress->locality_);
EXPECT_EQ("subLocality", geoAddress->subLocality_);
EXPECT_EQ("roadName", geoAddress->roadName_);
EXPECT_EQ("subRoadName", geoAddress->subRoadName_);
EXPECT_EQ("premises", geoAddress->premises_);
EXPECT_EQ("postalCode", geoAddress->postalCode_);
EXPECT_EQ("phoneNumber", geoAddress->phoneNumber_);
EXPECT_EQ("addressUrl", geoAddress->addressUrl_);
EXPECT_EQ(1, geoAddress->descriptions_.size());
auto iter = geoAddress->descriptions_.find(0);
EXPECT_EQ(true, iter != geoAddress->descriptions_.end());
EXPECT_EQ(0, iter->first);
EXPECT_EQ("line", iter->second);
EXPECT_EQ(true, geoAddress->isFromMock_);
}
#endif
#ifdef FEATURE_GEOCODE_SUPPORT
void LocationCommonTest::VerifyGeoAddressMarshalling(MessageParcel& newParcel)
{
EXPECT_EQ(MOCK_LATITUDE, newParcel.ReadDouble());
EXPECT_EQ(MOCK_LONGITUDE, newParcel.ReadDouble());
EXPECT_EQ("locale", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("placeName", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("countryCode", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("countryName", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("administrativeArea", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("subAdministrativeArea", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("locality", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("subLocality", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("roadName", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("subRoadName", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("premises", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("postalCode", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("phoneNumber", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ("addressUrl", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ(1, newParcel.ReadInt32());
EXPECT_EQ(0, newParcel.ReadInt32());
EXPECT_EQ("line", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ(true, newParcel.ReadBool());
}
#endif
void LocationCommonTest::VerifyLocationMarshalling(MessageParcel& newParcel)
{
EXPECT_EQ(VERIFY_LOCATION_LATITUDE, newParcel.ReadDouble());
EXPECT_EQ(VERIFY_LOCATION_LONGITUDE, newParcel.ReadDouble());
EXPECT_EQ(VERIFY_LOCATION_ALTITUDE, newParcel.ReadDouble());
EXPECT_EQ(VERIFY_LOCATION_ACCURACY, newParcel.ReadDouble());
EXPECT_EQ(VERIFY_LOCATION_SPEED, newParcel.ReadDouble());
EXPECT_EQ(VERIFY_LOCATION_DIRECTION, newParcel.ReadDouble());
EXPECT_EQ(VERIFY_LOCATION_TIME, newParcel.ReadInt64());
EXPECT_EQ(VERIFY_LOCATION_TIMESINCEBOOT, newParcel.ReadInt64());
EXPECT_EQ(1, newParcel.ReadInt64());
std::vector<std::u16string> additions;
newParcel.ReadString16Vector(&additions);
EXPECT_EQ("additions", Str16ToStr8(additions[0]));
EXPECT_EQ(1, newParcel.ReadInt32());
}
* @tc.name: GeoAddressTest001
* @tc.desc: read from parcel.
* @tc.type: FUNC
*/
#ifdef FEATURE_GEOCODE_SUPPORT
HWTEST_F(LocationCommonTest, GeoAddressTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, GeoAddressTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressTest001 begin");
std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
SetGeoAddress(geoAddress);
VerifyGeoAddressReadFromParcel(geoAddress);
MessageParcel newParcel;
geoAddress->Marshalling(newParcel);
VerifyGeoAddressMarshalling(newParcel);
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressTest001 end");
}
#endif
* @tc.name: GeoAddressTest001
* @tc.desc: read from parcel.
* @tc.type: FUNC
*/
#ifdef FEATURE_GEOCODE_SUPPORT
HWTEST_F(LocationCommonTest, GeoAddressTest002, TestSize.Level1)
{
std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
geoAddress->latitude_ = 1.0;
EXPECT_EQ(1.0, geoAddress->GetLatitude());
geoAddress->longitude_ = 1.0;
EXPECT_EQ(1.0, geoAddress->GetLongitude());
}
#endif
* @tc.name: LocationTest001
* @tc.desc: read from parcel.
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, LocationTest001, TestSize.Level0)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest001 begin");
auto location = std::make_shared<Location>();
MessageParcel parcel;
parcel.WriteDouble(VERIFY_LOCATION_LATITUDE);
parcel.WriteDouble(VERIFY_LOCATION_LONGITUDE);
parcel.WriteDouble(VERIFY_LOCATION_ALTITUDE);
parcel.WriteDouble(VERIFY_LOCATION_ACCURACY);
parcel.WriteDouble(VERIFY_LOCATION_SPEED);
parcel.WriteDouble(VERIFY_LOCATION_DIRECTION);
parcel.WriteInt64(VERIFY_LOCATION_TIME);
parcel.WriteInt64(VERIFY_LOCATION_TIMESINCEBOOT);
parcel.WriteInt64(1);
std::vector<std::u16string> additions;
additions.push_back(Str8ToStr16("additions"));
parcel.WriteString16Vector(additions);
parcel.WriteInt32(1);
location->ReadFromParcel(parcel);
EXPECT_EQ(VERIFY_LOCATION_LATITUDE, location->GetLatitude());
EXPECT_EQ(VERIFY_LOCATION_LONGITUDE, location->GetLongitude());
EXPECT_EQ(VERIFY_LOCATION_ALTITUDE, location->GetAltitude());
EXPECT_EQ(VERIFY_LOCATION_ACCURACY, location->GetAccuracy());
EXPECT_EQ(VERIFY_LOCATION_SPEED, location->GetSpeed());
EXPECT_EQ(VERIFY_LOCATION_DIRECTION, location->GetDirection());
EXPECT_EQ(VERIFY_LOCATION_TIME, location->GetTimeStamp());
EXPECT_EQ(VERIFY_LOCATION_TIMESINCEBOOT, location->GetTimeSinceBoot());
EXPECT_EQ(1, location->GetAdditionSize());
if (location->GetAdditions().size() == 1) {
EXPECT_EQ("additions", location->GetAdditions()[0]);
}
EXPECT_EQ(1, location->GetIsFromMock());
MessageParcel newParcel;
location->Marshalling(newParcel);
VerifyLocationMarshalling(newParcel);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest001 end");
}
* @tc.name: SateLLiteStatusTest001
* @tc.desc: read from parcel.
* @tc.type: FUNC
*/
#ifdef FEATURE_GNSS_SUPPORT
HWTEST_F(LocationCommonTest, SateLLiteStatusTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, SateLLiteStatusTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] SateLLiteStatusTest001 begin");
SatelliteStatus oldStatus;
std::unique_ptr<SatelliteStatus> status = std::make_unique<SatelliteStatus>(oldStatus);
MessageParcel parcel;
int sateNum = 2;
parcel.WriteInt64(2);
for (int i = 0; i < sateNum; i++) {
parcel.WriteInt64(i);
parcel.WriteDouble(i + 1.0);
parcel.WriteDouble(i + 2.0);
parcel.WriteDouble(i + 3.0);
parcel.WriteDouble(i + 4.0);
parcel.WriteInt64(i + 5.0);
parcel.WriteInt64(i + 6.0);
}
status->ReadFromParcel(parcel);
EXPECT_EQ(2, status->GetSatellitesNumber());
for (int i = 0; i < sateNum; i++) {
EXPECT_EQ(i, status->GetSatelliteIds()[i]);
EXPECT_EQ(i + 1.0, status->GetCarrierToNoiseDensitys()[i]);
EXPECT_EQ(i + 2.0, status->GetAltitudes()[i]);
EXPECT_EQ(i + 3.0, status->GetAzimuths()[i]);
EXPECT_EQ(i + 4.0, status->GetCarrierFrequencies()[i]);
EXPECT_EQ(i + 5.0, status->GetConstellationTypes()[i]);
EXPECT_EQ(i + 6.0, status->GetSatelliteAdditionalInfoList()[i]);
}
MessageParcel newParcel;
status->Marshalling(newParcel);
EXPECT_EQ(2, newParcel.ReadInt64());
for (int i = 0; i < sateNum; i++) {
EXPECT_EQ(i, newParcel.ReadInt64());
EXPECT_EQ(i + 1.0, newParcel.ReadDouble());
EXPECT_EQ(i + 2.0, newParcel.ReadDouble());
EXPECT_EQ(i + 3.0, newParcel.ReadDouble());
EXPECT_EQ(i + 4.0, newParcel.ReadDouble());
EXPECT_EQ(i + 5.0, newParcel.ReadInt64());
EXPECT_EQ(i + 6.0, newParcel.ReadInt64());
}
LBSLOGI(LOCATOR, "[LocationCommonTest] SateLLiteStatusTest001 end");
}
#endif
* @tc.name: RequestConfigTest001
* @tc.desc: read from parcel.
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, RequestConfigTest001, TestSize.Level0)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, RequestConfigTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest001 begin");
std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>();
MessageParcel parcel;
parcel.WriteInt32(1);
parcel.WriteInt32(2);
parcel.WriteInt32(3);
parcel.WriteDouble(10.0);
parcel.WriteFloat(1000.0);
parcel.WriteInt32(1);
requestConfig->ReadFromParcel(parcel);
EXPECT_EQ(1, requestConfig->GetScenario());
EXPECT_EQ(2, requestConfig->GetPriority());
EXPECT_EQ(3, requestConfig->GetTimeInterval());
EXPECT_EQ(10.0, requestConfig->GetDistanceInterval());
EXPECT_EQ(1000.0, requestConfig->GetMaxAccuracy());
EXPECT_EQ(1, requestConfig->GetFixNumber());
MessageParcel newParcel;
requestConfig->Marshalling(newParcel);
EXPECT_EQ(1, newParcel.ReadInt32());
EXPECT_EQ(2, newParcel.ReadInt32());
EXPECT_EQ(3, newParcel.ReadInt32());
EXPECT_EQ(10.0, newParcel.ReadDouble());
EXPECT_EQ(1000.0, newParcel.ReadFloat());
EXPECT_EQ(1, newParcel.ReadInt32());
LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest001 end");
}
HWTEST_F(LocationCommonTest, RequestConfigTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, RequestConfigTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest002 begin");
std::unique_ptr<RequestConfig> requestConfigForCompare =
std::make_unique<RequestConfig>();
RequestConfig requestConfigForSet1;
requestConfigForSet1.SetScenario(1);
requestConfigForSet1.SetPriority(2);
requestConfigForSet1.SetTimeInterval(3);
requestConfigForSet1.SetDistanceInterval(4.0);
requestConfigForSet1.SetMaxAccuracy(1000.0);
requestConfigForSet1.SetFixNumber(1);
requestConfigForCompare->Set(requestConfigForSet1);
EXPECT_NE("", requestConfigForCompare->ToString());
EXPECT_EQ(true, requestConfigForCompare->IsSame(requestConfigForSet1));
RequestConfig requestConfigForSet2;
requestConfigForSet2.SetScenario(2);
EXPECT_NE("", requestConfigForCompare->ToString());
EXPECT_EQ(false, requestConfigForCompare->IsSame(requestConfigForSet2));
RequestConfig requestConfigForSet3;
requestConfigForSet3.SetScenario(SCENE_UNSET);
requestConfigForSet3.SetPriority(2);
requestConfigForCompare->SetScenario(SCENE_UNSET);
EXPECT_NE("", requestConfigForCompare->ToString());
EXPECT_EQ(true, requestConfigForCompare->IsSame(requestConfigForSet3));
RequestConfig requestConfigForSet4;
requestConfigForSet4.SetScenario(SCENE_UNSET);
requestConfigForSet4.SetPriority(1);
requestConfigForCompare->SetScenario(SCENE_UNSET);
EXPECT_NE("", requestConfigForCompare->ToString());
EXPECT_EQ(false, requestConfigForCompare->IsSame(requestConfigForSet4));
LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest002 end");
}
* @tc.name: GeocodingMockInfoTest001
* @tc.desc: read from parcel.
* @tc.type: FUNC
*/
#ifdef FEATURE_GEOCODE_SUPPORT
HWTEST_F(LocationCommonTest, GeocodingMockInfoTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, GeocodingMockInfoTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest001 begin");
MessageParcel parcel;
parcel.WriteString16(Str8ToStr16("locale"));
parcel.WriteDouble(12.0);
parcel.WriteDouble(13.0);
parcel.WriteInt32(1);
std::unique_ptr<GeocodingMockInfo> mockInfo = std::make_unique<GeocodingMockInfo>();
mockInfo->ReadFromParcel(parcel);
std::shared_ptr<ReverseGeocodeRequest> reverseGeocodeRequest = mockInfo->GetLocation();
EXPECT_EQ(true, reverseGeocodeRequest != nullptr);
EXPECT_EQ("locale", reverseGeocodeRequest->locale);
EXPECT_EQ(12.0, reverseGeocodeRequest->latitude);
EXPECT_EQ(13.0, reverseGeocodeRequest->longitude);
EXPECT_EQ(1, reverseGeocodeRequest->maxItems);
MessageParcel newParcel;
mockInfo->Marshalling(newParcel);
EXPECT_EQ("locale", Str16ToStr8(newParcel.ReadString16()));
EXPECT_EQ(12.0, newParcel.ReadDouble());
EXPECT_EQ(13.0, newParcel.ReadDouble());
EXPECT_EQ(1, newParcel.ReadInt32());
GeocodingMockInfo::Unmarshalling(newParcel);
LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest001 end");
}
#endif
HWTEST_F(LocationCommonTest, AppIdentityTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest001 begin");
AppIdentity identity;
identity.SetPid(1);
identity.SetUid(2);
identity.SetTokenId(3);
identity.SetFirstTokenId(4);
identity.SetBundleName("bundleName");
EXPECT_EQ(1, identity.GetPid());
EXPECT_EQ(2, identity.GetUid());
EXPECT_EQ(3, identity.GetTokenId());
EXPECT_EQ(4, identity.GetFirstTokenId());
EXPECT_EQ("bundleName", identity.GetBundleName());
EXPECT_NE("", identity.ToString());
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest001 end");
}
#ifdef FEATURE_GEOCODE_SUPPORT
HWTEST_F(LocationCommonTest, GeocodingMockInfoTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, GeocodingMockInfoTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest002 begin");
std::unique_ptr<GeocodingMockInfo> mockInfo = std::make_unique<GeocodingMockInfo>();
auto reverseGeocodeRequest = std::make_shared<ReverseGeocodeRequest>();
mockInfo->SetLocation(reverseGeocodeRequest);
EXPECT_NE(nullptr, mockInfo->GetLocation());
std::shared_ptr<GeoAddress> geoAddress = std::make_shared<GeoAddress>();
mockInfo->SetGeoAddressInfo(geoAddress);
EXPECT_NE(nullptr, mockInfo->GetGeoAddressInfo());
LBSLOGI(LOCATOR, "[LocationCommonTest] GeocodingMockInfoTest002 end");
}
#endif
HWTEST_F(LocationCommonTest, PermStateChangeCallbackTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, PermStateChangeCallbackTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] PermStateChangeCallbackTest001 begin");
uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
PermStateChangeScope scopeInfo;
scopeInfo.permList = {"ohos.permission.LOCATION"};
scopeInfo.tokenIDs = {callingTokenId};
auto callbackPtr = std::make_shared<PermissionStatusChangeCb>(scopeInfo);
struct PermStateChangeInfo result{0, callingTokenId, ACCESS_LOCATION};
ASSERT_TRUE(callbackPtr != nullptr);
callbackPtr->PermStateChangeCallback(result);
LBSLOGI(LOCATOR, "[LocationCommonTest] PermStateChangeCallbackTest001 end");
}
HWTEST_F(LocationCommonTest, LocatorEventSubscriberTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocatorEventSubscriberTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest001 begin");
OHOS::EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_LOCATION_MODE_STATE_CHANGED);
OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
auto locatorEventSubscriber = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
Want want;
want.SetAction("usual.event.location.MODE_STATE_CHANGED");
OHOS::EventFwk::CommonEventData data;
data.SetWant(want);
ASSERT_TRUE(locatorEventSubscriber != nullptr);
locatorEventSubscriber->OnReceiveEvent(data);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest001 end");
}
HWTEST_F(LocationCommonTest, LocatorEventSubscriberTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocatorEventSubscriberTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest002 begin");
OHOS::EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_LOCATION_MODE_STATE_CHANGED);
OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
auto locatorEventSubscriber = std::make_shared<LocatorEventSubscriber>(subscriberInfo);
Want want;
want.SetAction("Invalid action");
OHOS::EventFwk::CommonEventData data;
data.SetWant(want);
ASSERT_TRUE(locatorEventSubscriber != nullptr);
locatorEventSubscriber->OnReceiveEvent(data);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocatorEventSubscriberTest002 end");
}
#ifdef FEATURE_GEOCODE_SUPPORT
HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, GeoAddressDescriptionsTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest001 begin");
std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
SetGeoAddress(geoAddress);
EXPECT_EQ("line", geoAddress->GetDescriptions(0));
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest001 end");
}
#endif
#ifdef FEATURE_GEOCODE_SUPPORT
HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, GeoAddressDescriptionsTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest002 begin");
std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
SetGeoAddress(geoAddress);
EXPECT_EQ("", geoAddress->GetDescriptions(1));
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest002 end");
}
#endif
#ifdef FEATURE_GEOCODE_SUPPORT
HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, GeoAddressDescriptionsTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest003 begin");
std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
SetGeoAddress(geoAddress);
EXPECT_EQ("", geoAddress->GetDescriptions(-1));
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest003 end");
}
#endif
HWTEST_F(LocationCommonTest, LoadLocationSaTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LoadLocationSaTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest001 begin");
LocationErrCode err = LocationSaLoadManager::GetInstance()->LoadLocationSa(UN_SAID);
EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
err = LocationSaLoadManager::GetInstance()->LoadLocationSa(LOCATION_LOCATOR_SA_ID);
LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest001 end");
}
HWTEST_F(LocationCommonTest, LoadLocationSaTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LoadLocationSaTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest002 begin");
LocationErrCode err = LocationSaLoadManager::GetInstance()->UnloadLocationSa(UN_SAID);
EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
err = LocationSaLoadManager::GetInstance()->UnloadLocationSa(LOCATION_NOPOWER_LOCATING_SA_ID);
EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest002 end");
}
HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationDataRdbHelperTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest001 begin");
Uri unknownUri(UN_URI);
auto dataRdbObserver = sptr<LocationDataRdbObserver>(new (std::nothrow) LocationDataRdbObserver());
LocationErrCode err =
LocationDataRdbHelper::GetInstance()->RegisterDataObserver(unknownUri, dataRdbObserver);
EXPECT_EQ(ERRCODE_SUCCESS, err);
err = LocationDataRdbHelper::GetInstance()->UnregisterDataObserver(unknownUri, dataRdbObserver);
EXPECT_EQ(ERRCODE_SUCCESS, err);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest001 end");
}
HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationDataRdbHelperTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest002 begin");
Uri locationDataEnableUri(LocationDataRdbManager::GetLocationDataUriByCurrentUserId("location_enable"));
int32_t state = DISABLED;
LocationDataRdbHelper::GetInstance()->SetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state);
LocationDataRdbHelper::GetInstance()->GetValue(locationDataEnableUri, LOCATION_DATA_COLUMN_ENABLE, state);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest002 end");
}
HWTEST_F(LocationCommonTest, LocationDataRdbHelperTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationDataRdbHelperTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest003 begin");
Uri unknownUri(UN_URI);
int32_t state = DISABLED;
LocationDataRdbHelper::GetInstance()->SetValue(unknownUri, LOCATION_DATA_COLUMN_ENABLE, state);
EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, LocationDataRdbHelper::GetInstance()->
GetValue(unknownUri, LOCATION_DATA_COLUMN_ENABLE, state));
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbHelperTest003 end");
}
HWTEST_F(LocationCommonTest, LocationSaLoadManager002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationSaLoadManager002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationSaLoadManager002 begin");
LocationSaLoadManager::GetInstance()->LoadSystemAbilityFail();
auto locationSaLoadCallback = sptr<LocationSaLoadCallback>(new LocationSaLoadCallback());
ASSERT_TRUE(locationSaLoadCallback != nullptr);
locationSaLoadCallback->OnLoadSystemAbilityFail(0);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationSaLoadManager002 end");
}
HWTEST_F(LocationCommonTest, GeoAddressDescriptionsTest004, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, GeoAddressDescriptionsTest004, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest004 begin");
std::unique_ptr<GeoAddress> geoAddress = std::make_unique<GeoAddress>();
geoAddress->descriptionsSize_ = 1;
EXPECT_EQ("", geoAddress->GetDescriptions(-1));
LBSLOGI(LOCATOR, "[LocationCommonTest] GeoAddressDescriptionsTest004 end");
}
HWTEST_F(LocationCommonTest, LocationTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest002 begin");
auto location = std::make_shared<Location>();
location->SetLatitude(VERIFY_LOCATION_LATITUDE);
location->SetLongitude(VERIFY_LOCATION_LONGITUDE);
location->SetAltitude(VERIFY_LOCATION_ALTITUDE);
location->SetAccuracy(VERIFY_LOCATION_ACCURACY);
location->SetSpeed(VERIFY_LOCATION_SPEED);
location->SetDirection(VERIFY_LOCATION_DIRECTION);
location->SetTimeStamp(VERIFY_LOCATION_TIME);
location->SetTimeSinceBoot(VERIFY_LOCATION_TIMESINCEBOOT);
std::vector<std::string> additions;
additions.push_back("additions");
location->SetAdditions(additions, false);
location->SetAdditionSize(1);
location->SetIsFromMock(1);
location->ToString();
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationTest002 end");
}
HWTEST_F(LocationCommonTest, AppIdentityTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest002 begin");
AppIdentity identity(1, 2, 3, 4, 5);
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest002 end");
}
HWTEST_F(LocationCommonTest, RequestConfigTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, RequestConfigTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest003 begin");
std::unique_ptr<RequestConfig> requestConfig = std::make_unique<RequestConfig>(1);
ASSERT_TRUE(requestConfig != nullptr);
LBSLOGI(LOCATOR, "[LocationCommonTest] RequestConfigTest003 end");
}
#define LOCATION_LOADSA_TIMEOUT_MS_FOR_TEST = 0
#define LOCATION_LOADSA_TIMEOUT_MS LOCATION_LOADSA_TIMEOUT_MS_FOR_TEST
HWTEST_F(LocationCommonTest, LoadLocationSaTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LoadLocationSaTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest003 begin");
LocationErrCode err =
LocationSaLoadManager::GetInstance()->WaitLoadStateChange(LOCATION_LOCATOR_SA_ID);
EXPECT_EQ(ERRCODE_SERVICE_UNAVAILABLE, err);
LBSLOGI(LOCATOR, "[LocationCommonTest] LoadLocationSaTest003 end");
}
#undef LOCATION_LOADSA_TIMEOUT_MS
#undef LOCATION_LOADSA_TIMEOUT_MS_FOR_TEST
static int OhosHookTest01(const HOOK_INFO *hookInfo, void *executionContext)
{
LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
EXPECT_NE(hookInfo, nullptr);
EXPECT_EQ(hookInfo->prio, 0);
EXPECT_EQ(executionContext, nullptr);
return 0;
}
static int OhosHookTest02(const HOOK_INFO *hookInfo, void *executionContext)
{
LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
EXPECT_NE(hookInfo, nullptr);
EXPECT_EQ(hookInfo->prio, 1);
EXPECT_EQ(executionContext, nullptr);
return 0;
}
typedef struct hookTestStruct {
const char *hookTestName;
LocationProcessStage state;
} HOOK_TEST;
static int OhosHookTest03(const HOOK_INFO *hookInfo, void *executionContext)
{
LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
EXPECT_NE(hookInfo, nullptr);
EXPECT_EQ(hookInfo->prio, 0);
EXPECT_NE(executionContext, nullptr);
HOOK_TEST* hookTest = (HOOK_TEST*)executionContext;
EXPECT_NE(hookTest, nullptr);
LocationProcessStage state = hookTest->state;
const char *hookTestName = hookTest->hookTestName;
EXPECT_EQ(state, LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS);
EXPECT_EQ(hookTestName, "HookUtils002");
return 0;
}
static int OhosHookTest04(const HOOK_INFO *hookInfo, void *executionContext)
{
LBSLOGI(LOCATOR, "[LocationCommonTest] %{public}s enter", __func__);
EXPECT_NE(hookInfo, nullptr);
EXPECT_EQ(hookInfo->prio, 1);
EXPECT_NE(executionContext, nullptr);
HOOK_TEST* hookTest = (HOOK_TEST*)executionContext;
EXPECT_NE(hookTest, nullptr);
LocationProcessStage state = hookTest->state;
const char *hookTestName = hookTest->hookTestName;
EXPECT_EQ(state, LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS);
EXPECT_EQ(hookTestName, "HookUtils002");
return 0;
}
HWTEST_F(LocationCommonTest, HookUtils001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, HookUtils001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils001 begin");
ASSERT_TRUE(HookUtils::GetLocationExtHookMgr() != nullptr);
EXPECT_EQ(ERRCODE_SUCCESS,
HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, 0, OhosHookTest01));
EXPECT_EQ(ERRCODE_SUCCESS,
HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, 1, OhosHookTest02));
EXPECT_EQ(ERRCODE_SUCCESS,
HookUtils::ExecuteHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, nullptr, nullptr));
HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, OhosHookTest01);
HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_START_LOCATING, OhosHookTest02);
LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils001 end");
}
HWTEST_F(LocationCommonTest, HookUtils002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, HookUtils002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils002 begin");
ASSERT_TRUE(HookUtils::GetLocationExtHookMgr() != nullptr);
EXPECT_EQ(ERRCODE_SUCCESS,
HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, 0, OhosHookTest03));
EXPECT_EQ(ERRCODE_SUCCESS,
HookUtils::RegisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, 1, OhosHookTest04));
HOOK_TEST hookTestStruct;
hookTestStruct.hookTestName = "HookUtils002";
hookTestStruct.state = LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS;
EXPECT_EQ(ERRCODE_SUCCESS,
HookUtils::ExecuteHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, (void *)(&hookTestStruct), nullptr));
HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, OhosHookTest03);
HookUtils::UnregisterHook(LocationProcessStage::LOCATOR_SA_REQUEST_PROCESS, OhosHookTest04);
LBSLOGI(LOCATOR, "[LocationCommonTest] HookUtils002 end");
}
HWTEST_F(LocationCommonTest, Request001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->requestConfig_ = nullptr;
RequestConfig requestConfig;
request->SetRequestConfig(requestConfig);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request001 end");
}
HWTEST_F(LocationCommonTest, Request002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
int type = 1;
request->SetPermUsedType(type);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request002 end");
}
HWTEST_F(LocationCommonTest, Request003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
std::shared_ptr<std::list<std::string>> proxys;
proxys = nullptr;
request->GetProxyName(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request003 end");
}
HWTEST_F(LocationCommonTest, Request004, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request004, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->requestConfig_ = nullptr;
std::shared_ptr<std::list<std::string>> proxys;
request->GetProxyName(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request004 end");
}
HWTEST_F(LocationCommonTest, Request005, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request005, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
request->GetProxyName(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request005 end");
}
HWTEST_F(LocationCommonTest, Request006, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request006, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->requestConfig_ = nullptr;
std::shared_ptr<std::list<std::string>> proxys;
proxys = nullptr;
request->GetProxyName(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request006 end");
}
HWTEST_F(LocationCommonTest, Request007, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request007, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = SCENE_NAVIGATION;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = LOCATION_SCENE_LOW_POWER_CONSUMPTION;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = LOCATION_SCENE_DAILY_LIFE_SERVICE;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = SCENE_DAILY_LIFE_SERVICE;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = LOCATION_SCENE_NO_POWER_CONSUMPTION;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = SCENE_NO_POWER;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = SCENE_UNSET;
request->GetProxyName(proxys);
request->requestConfig_->scenario_ = 0;
request->GetProxyName(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request007 end");
}
HWTEST_F(LocationCommonTest, Request008, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request008, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->requestConfig_ = nullptr;
request->ToString();
LBSLOGI(LOCATOR, "[LocationCommonTest] Request008 end");
}
HWTEST_F(LocationCommonTest, Request009, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request009, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->requestConfig_->scenario_ = SCENE_NAVIGATION;
request->SetNlpRequestType();
request->requestConfig_->scenario_ = SCENE_TRAJECTORY_TRACKING;
request->SetNlpRequestType();
request->requestConfig_->scenario_ = SCENE_CAR_HAILING;
request->SetNlpRequestType();
request->requestConfig_->scenario_ = LOCATION_SCENE_NAVIGATION;
request->SetNlpRequestType();
request->requestConfig_->scenario_ = LOCATION_SCENE_SPORT;
request->SetNlpRequestType();
request->requestConfig_->scenario_ = LOCATION_SCENE_TRANSPORT;
request->SetNlpRequestType();
request->requestConfig_->scenario_ = LOCATION_SCENE_HIGH_POWER_CONSUMPTION;
request->SetNlpRequestType();
request->requestConfig_->priority_ = PRIORITY_ACCURACY;
request->SetNlpRequestType();
request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX;
request->SetNlpRequestType();
request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY;
request->SetNlpRequestType();
request->requestConfig_->priority_ = 0;
request->SetNlpRequestType();
request->requestConfig_->scenario_ = 0;
request->SetNlpRequestType();
LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 end");
}
HWTEST_F(LocationCommonTest, Request010, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request009, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request009 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->lastLocation_ = nullptr;
const std::unique_ptr<Location> location;
request->SetLastLocation(location);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request010 end");
}
HWTEST_F(LocationCommonTest, Request011, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request011, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
std::shared_ptr<std::list<std::string>> proxys;
proxys = nullptr;
request->GetProxyNameByPriority(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request011 end");
}
HWTEST_F(LocationCommonTest, Request012, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request012, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->requestConfig_ = nullptr;
std::shared_ptr<std::list<std::string>> proxys;
proxys = nullptr;
request->GetProxyNameByPriority(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request012 end");
}
HWTEST_F(LocationCommonTest, Request013, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request013, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->requestConfig_ = nullptr;
std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
request->GetProxyNameByPriority(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request013 end");
}
HWTEST_F(LocationCommonTest, Request014, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request014, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
std::shared_ptr<std::list<std::string>> proxys = std::make_shared<std::list<std::string>>();
request->requestConfig_->priority_ = PRIORITY_LOW_POWER;
request->GetProxyName(proxys);
request->requestConfig_->priority_ = LOCATION_PRIORITY_ACCURACY;
request->GetProxyName(proxys);
request->requestConfig_->priority_ = LOCATION_PRIORITY_LOCATING_SPEED;
request->GetProxyName(proxys);
request->requestConfig_->priority_ = PRIORITY_ACCURACY;
request->GetProxyName(proxys);
request->requestConfig_->priority_ = PRIORITY_FAST_FIRST_FIX;
request->GetProxyName(proxys);
request->requestConfig_->priority_ = 0;
request->GetProxyName(proxys);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request014 end");
}
HWTEST_F(LocationCommonTest, Request015, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Request015, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 begin");
std::unique_ptr<Request> request = std::make_unique<Request>();
request->GetLocationPermState();
request->GetBackgroundPermState();
bool state = true;
request->SetLocationPermState(state);
request->SetBackgroundPermState(state);
request->SetApproximatelyPermState(state);
sptr<ILocatorCallback> callback;
request->SetLocationErrorCallBack(callback);
LBSLOGI(LOCATOR, "[LocationCommonTest] Request015 end");
}
HWTEST_F(LocationCommonTest, Location001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Location001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 begin");
std::unique_ptr<Location> location1 = std::make_unique<Location>();
std::unique_ptr<Location> location2 = std::make_unique<Location>();
location2->latitude_ = MIN_LATITUDE + 1;
location1->LocationEqual(location2);
location2->latitude_ = MIN_LATITUDE - 1;
location2->longitude_ = MIN_LONGITUDE + 1;
location1->LocationEqual(location2);
location2->longitude_ = MIN_LONGITUDE - 1;
location2->altitude_ = 1.0;
location1->LocationEqual(location2);
location2->altitude_ = 0.0;
location2->accuracy_ = 1.0;
location1->LocationEqual(location2);
location2->accuracy_ = 0.0;
location2->speed_ = 1.0;
location1->LocationEqual(location2);
location2->speed_ = 0.0;
location2->direction_ = 1.0;
location1->LocationEqual(location2);
location2->direction_ = 0.0;
location2->timeStamp_ = 1;
location1->LocationEqual(location2);
location2->timeStamp_ = 0;
location2->timeSinceBoot_ = 1;
location1->LocationEqual(location2);
location2->timeSinceBoot_ = 0;
std::vector<std::string> additions;
location2->additions_ = additions;
location2->additionSize_ = 1;
location1->LocationEqual(location2);
location2->additionSize_ = 0;
location2->isFromMock_ = true;
location1->LocationEqual(location2);
location2->isFromMock_ = false;
location1->LocationEqual(location2);
LBSLOGI(LOCATOR, "[LocationCommonTest] Location001 end");
}
HWTEST_F(LocationCommonTest, Location002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Location002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 begin");
std::unique_ptr<Location> location1 = std::make_unique<Location>();
std::unique_ptr<Location> location2 = nullptr;
location1->LocationEqual(location2);
LBSLOGI(LOCATOR, "[LocationCommonTest] Location002 end");
}
HWTEST_F(LocationCommonTest, Location003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Location003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 begin");
std::unique_ptr<Location> location1 = std::make_unique<Location>();
std::unique_ptr<Location> location2 = nullptr;
location1->AdditionEqual(location2);
LBSLOGI(LOCATOR, "[LocationCommonTest] Location003 end");
}
HWTEST_F(LocationCommonTest, Location004, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Location004, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 begin");
std::unique_ptr<Location> location1 = std::make_unique<Location>();
std::vector<std::string> additions;
location1->additions_ = additions;
std::unique_ptr<Location> location2 = std::make_unique<Location>();
location2->additions_ = additions;
location1->AdditionEqual(location2);
LBSLOGI(LOCATOR, "[LocationCommonTest] Location004 end");
}
HWTEST_F(LocationCommonTest, Location005, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Location005, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 begin");
std::unique_ptr<Location> location1 = std::make_unique<Location>();
std::vector<std::string> additions;
location1->additions_ = additions;
std::unique_ptr<Location> location2 = std::make_unique<Location>();
additions.resize(5);
location2->additions_ = additions;
location1->AdditionEqual(location2);
LBSLOGI(LOCATOR, "[LocationCommonTest] Location005 end");
}
HWTEST_F(LocationCommonTest, Location006, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, Location006, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 begin");
std::unique_ptr<Location> location1 = std::make_unique<Location>();
std::vector<std::string> additions1(4, "1");
location1->additions_ = additions1;
std::unique_ptr<Location> location2 = std::make_unique<Location>();
std::vector<std::string> additions2(4, "2");
location2->additions_ = additions2;
location1->AdditionEqual(location2);
LBSLOGI(LOCATOR, "[LocationCommonTest] Location006 end");
}
HWTEST_F(LocationCommonTest, LbsResLoader001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LbsResLoader001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LbsResLoader001 begin");
LbsResLoader resLoader;
std::string countryCodeStr8 = resLoader.GetSystemRegion();
countryCodeStr8 = resLoader.GetSystemRegion();
EXPECT_NE(countryCodeStr8, "");
LBSLOGI(LOCATOR, "[LocationCommonTest] LbsResLoader001 end");
}
HWTEST_F(LocationCommonTest, LocationDataRdbManagerTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationDataRdbManagerTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest001 begin");
std::string state;
bool ret =
LocationDataRdbManager::GetIntelligentStatus("testuri", "testuri", "testColName", state);
EXPECT_EQ(false, ret);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest001 end");
}
HWTEST_F(LocationCommonTest, LocationDataRdbManagerTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, LocationDataRdbManagerTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest002 begin");
std::string state;
bool ret =
LocationDataRdbManager::SetGnssSessionState(0, "testuri", "testColName");
EXPECT_EQ(false, ret);
LBSLOGI(LOCATOR, "[LocationCommonTest] LocationDataRdbManagerTest002 end");
}
* @tc.name: WriteGnssStateEventTest001
* @tc.desc: test WriteGnssStateEvent with normal params
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteGnssStateEventTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteGnssStateEventTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteGnssStateEventTest001 begin");
WriteGnssStateEvent("start", 1000, 1000);
WriteGnssStateEvent("stop", 2000, 2000);
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteGnssStateEventTest001 end");
}
* @tc.name: WriteAppLocatingStateEventTest001
* @tc.desc: test WriteAppLocatingStateEvent with normal params
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteAppLocatingStateEventTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteAppLocatingStateEventTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteAppLocatingStateEventTest001 begin");
WriteAppLocatingStateEvent("start", 1000, 1000);
WriteAppLocatingStateEvent("stop", 2000, 2000);
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteAppLocatingStateEventTest001 end");
}
* @tc.name: WriteLocationSwitchStateEventTest001
* @tc.desc: test WriteLocationSwitchStateEvent with normal params
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationSwitchStateEventTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationSwitchStateEventTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationSwitchStateEventTest001 begin");
WriteLocationSwitchStateEvent("on", "com.example.app", 100);
WriteLocationSwitchStateEvent("off", "com.example.app", 100);
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationSwitchStateEventTest001 end");
}
* @tc.name: WriteLocationInnerEventTest001
* @tc.desc: test WriteLocationInnerEvent with initializer_list, even number of params
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationInnerEventTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationInnerEventTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest001 begin");
WriteLocationInnerEvent(SA_LOAD, {"saId", "1", "type", "load", "ret", "1"});
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest001 end");
}
* @tc.name: WriteLocationInnerEventTest002
* @tc.desc: test WriteLocationInnerEvent with initializer_list, odd number of params
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationInnerEventTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationInnerEventTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest002 begin");
WriteLocationInnerEvent(SA_LOAD, {"saId", "1", "type"});
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest002 end");
}
* @tc.name: WriteLocationInnerEventTest003
* @tc.desc: test WriteLocationInnerEvent with initializer_list, empty params
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationInnerEventTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationInnerEventTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest003 begin");
WriteLocationInnerEvent(SA_LOAD, {});
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest003 end");
}
* @tc.name: WriteLocationInnerEventTest004
* @tc.desc: test WriteLocationInnerEvent with vectors overload
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationInnerEventTest004, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationInnerEventTest004, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest004 begin");
std::vector<std::string> names = {"saId", "type", "ret"};
std::vector<std::string> values = {"1", "load", "1"};
WriteLocationInnerEvent(SA_LOAD, names, values);
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest004 end");
}
* @tc.name: WriteLocationInnerEventTest005
* @tc.desc: test WriteLocationInnerEvent with vectors overload, empty vectors
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationInnerEventTest005, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationInnerEventTest005, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest005 begin");
std::vector<std::string> names;
std::vector<std::string> values;
WriteLocationInnerEvent(SA_LOAD, names, values);
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationInnerEventTest005 end");
}
* @tc.name: WriteLocationRequestEventTest001
* @tc.desc: test WriteLocationRequestEvent with empty packageName
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationRequestEventTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationRequestEventTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest001 begin");
WriteLocationRequestEvent("", "gps");
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest001 end");
}
* @tc.name: WriteLocationRequestEventTest002
* @tc.desc: test WriteLocationRequestEvent with valid packageName and gps ability
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationRequestEventTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationRequestEventTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest002 begin");
WriteLocationRequestEvent("com.example.app", "gps");
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest002 end");
}
* @tc.name: WriteLocationRequestEventTest003
* @tc.desc: test WriteLocationRequestEvent with valid packageName and passive ability
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationRequestEventTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationRequestEventTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest003 begin");
WriteLocationRequestEvent("com.example.app", "passive");
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest003 end");
}
* @tc.name: WriteLocationRequestEventTest004
* @tc.desc: test WriteLocationRequestEvent with valid packageName and network ability
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationRequestEventTest004, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationRequestEventTest004, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest004 begin");
WriteLocationRequestEvent("com.example.app", "network");
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest004 end");
}
* @tc.name: WriteLocationRequestEventTest005
* @tc.desc: test WriteLocationRequestEvent with valid packageName and unknown ability
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, WriteLocationRequestEventTest005, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, WriteLocationRequestEventTest005, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest005 begin");
WriteLocationRequestEvent("com.example.app", "unknown_ability");
LBSLOGI(LOCATOR, "[LocationCommonTest] WriteLocationRequestEventTest005 end");
}
* @tc.name: AppIdentityTest003
* @tc.desc: test parameterized constructor sets all fields correctly
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, AppIdentityTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest003 begin");
AppIdentity identity(100, 200, 300, 400, 500);
EXPECT_EQ(100, identity.GetUid());
EXPECT_EQ(200, identity.GetPid());
EXPECT_EQ(300u, identity.GetTokenId());
EXPECT_EQ(400u, identity.GetTokenIdEx());
EXPECT_EQ(500u, identity.GetFirstTokenId());
EXPECT_EQ("", identity.GetBundleName());
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest003 end");
}
* @tc.name: AppIdentityTest004
* @tc.desc: test default constructor initializes all fields to zero/empty
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, AppIdentityTest004, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest004, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest004 begin");
AppIdentity identity;
EXPECT_EQ(0, identity.GetUid());
EXPECT_EQ(0, identity.GetPid());
EXPECT_EQ(0u, identity.GetTokenId());
EXPECT_EQ(0u, identity.GetTokenIdEx());
EXPECT_EQ(0u, identity.GetFirstTokenId());
EXPECT_EQ("", identity.GetBundleName());
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest004 end");
}
* @tc.name: AppIdentityTest005
* @tc.desc: test SetTokenIdEx and GetTokenIdEx
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, AppIdentityTest005, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest005, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest005 begin");
AppIdentity identity;
identity.SetTokenIdEx(12345678);
EXPECT_EQ(12345678u, identity.GetTokenIdEx());
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest005 end");
}
* @tc.name: AppIdentityTest006
* @tc.desc: test ReadFromParcel and Marshalling round-trip
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, AppIdentityTest006, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest006, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest006 begin");
AppIdentity identity(100, 200, 300, 400, 500);
identity.SetBundleName("com.test.bundle");
MessageParcel parcel;
EXPECT_EQ(true, identity.Marshalling(parcel));
AppIdentity identity2;
identity2.ReadFromParcel(parcel);
EXPECT_EQ(100, identity2.GetUid());
EXPECT_EQ(200, identity2.GetPid());
EXPECT_EQ(300u, identity2.GetTokenId());
EXPECT_EQ(400u, identity2.GetTokenIdEx());
EXPECT_EQ(500u, identity2.GetFirstTokenId());
EXPECT_EQ("com.test.bundle", identity2.GetBundleName());
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest006 end");
}
* @tc.name: AppIdentityTest007
* @tc.desc: test Unmarshalling static method
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, AppIdentityTest007, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest007, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest007 begin");
AppIdentity identity(100, 200, 300, 400, 500);
identity.SetBundleName("com.test.unmarshalling");
MessageParcel parcel;
identity.Marshalling(parcel);
AppIdentity* identityPtr = AppIdentity::Unmarshalling(parcel);
ASSERT_TRUE(identityPtr != nullptr);
EXPECT_EQ(100, identityPtr->GetUid());
EXPECT_EQ(200, identityPtr->GetPid());
EXPECT_EQ(300u, identityPtr->GetTokenId());
EXPECT_EQ(400u, identityPtr->GetTokenIdEx());
EXPECT_EQ(500u, identityPtr->GetFirstTokenId());
EXPECT_EQ("com.test.unmarshalling", identityPtr->GetBundleName());
delete identityPtr;
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest007 end");
}
* @tc.name: AppIdentityTest008
* @tc.desc: test UnmarshallingShared static method
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, AppIdentityTest008, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest008, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest008 begin");
AppIdentity identity(100, 200, 300, 400, 500);
identity.SetBundleName("com.test.unmarshallingshared");
MessageParcel parcel;
identity.Marshalling(parcel);
std::shared_ptr<AppIdentity> identityShared = AppIdentity::UnmarshallingShared(parcel);
ASSERT_TRUE(identityShared != nullptr);
EXPECT_EQ(100, identityShared->GetUid());
EXPECT_EQ(200, identityShared->GetPid());
EXPECT_EQ(300u, identityShared->GetTokenId());
EXPECT_EQ(400u, identityShared->GetTokenIdEx());
EXPECT_EQ(500u, identityShared->GetFirstTokenId());
EXPECT_EQ("com.test.unmarshallingshared", identityShared->GetBundleName());
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest008 end");
}
* @tc.name: AppIdentityTest009
* @tc.desc: test ToString with parameterized constructor
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, AppIdentityTest009, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, AppIdentityTest009, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest009 begin");
AppIdentity identity(100, 200, 300, 400, 500);
std::string str = identity.ToString();
EXPECT_NE(std::string::npos, str.find("uid : 100"));
EXPECT_NE(std::string::npos, str.find("pid : 200"));
EXPECT_NE(std::string::npos, str.find("bundleName : "));
LBSLOGI(LOCATOR, "[LocationCommonTest] AppIdentityTest009 end");
}
* @tc.name: SaLoadWithStatisticTest001
* @tc.desc: test SaLoadWithStatistic constructor and destructor
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, SaLoadWithStatisticTest001, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, SaLoadWithStatisticTest001, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest001 begin");
SaLoadWithStatistic saLoader;
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest001 end");
}
* @tc.name: SaLoadWithStatisticTest002
* @tc.desc: test SaLoadWithStatistic::InitLocationSa with invalid saId
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, SaLoadWithStatisticTest002, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, SaLoadWithStatisticTest002, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest002 begin");
bool ret = SaLoadWithStatistic::InitLocationSa(UN_SAID);
EXPECT_EQ(false, ret);
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest002 end");
}
* @tc.name: SaLoadWithStatisticTest003
* @tc.desc: test SaLoadWithStatistic::UnInitLocationSa with invalid saId (already unloaded)
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, SaLoadWithStatisticTest003, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, SaLoadWithStatisticTest003, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest003 begin");
bool ret = SaLoadWithStatistic::UnInitLocationSa(UN_SAID);
EXPECT_EQ(true, ret);
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest003 end");
}
* @tc.name: SaLoadWithStatisticTest004
* @tc.desc: test SaLoadWithStatistic::InitLocationSa with LOCATION_LOCATOR_SA_ID
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, SaLoadWithStatisticTest004, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, SaLoadWithStatisticTest004, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest004 begin");
bool ret = SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID);
EXPECT_EQ(true, ret);
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest004 end");
}
* @tc.name: SaLoadWithStatisticTest005
* @tc.desc: test SaLoadWithStatistic::InitLocationSa called twice (already loaded branch)
* @tc.type: FUNC
*/
HWTEST_F(LocationCommonTest, SaLoadWithStatisticTest005, TestSize.Level1)
{
GTEST_LOG_(INFO)
<< "LocationCommonTest, SaLoadWithStatisticTest005, TestSize.Level1";
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest005 begin");
SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID);
bool ret = SaLoadWithStatistic::InitLocationSa(LOCATION_LOCATOR_SA_ID);
EXPECT_EQ(true, ret);
LBSLOGI(LOCATOR, "[LocationCommonTest] SaLoadWithStatisticTest005 end");
}
}
}