From 184b200c5b7f9ae913e6303cf64470482d2c80ba Mon Sep 17 00:00:00 2001 From: z30025928 <734222381@qq.com> Date: Fri, 17 Feb 2023 16:31:04 +0800 Subject: [PATCH] pick to monthly Signed-off-by: z30025928 <734222381@qq.com> --- .../include/location_config_manager_test.h | 1 + .../source/location_config_manager_test.cpp | 21 ++++++++++++++++-- .../location_without_permission_test.cpp | 22 ++++++++++--------- .../source/locator_service_test.cpp | 4 ++-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/test/location_locator/include/location_config_manager_test.h b/test/location_locator/include/location_config_manager_test.h index 6b4bf5fdb..81906b043 100644 --- a/test/location_locator/include/location_config_manager_test.h +++ b/test/location_locator/include/location_config_manager_test.h @@ -24,6 +24,7 @@ class LocationConfigManagerTest : public testing::Test { public: void SetUp(); void TearDown(); + std::string GetLocationSwitchConfigPath(); }; } // namespace Location } // namespace OHOS diff --git a/test/location_locator/source/location_config_manager_test.cpp b/test/location_locator/source/location_config_manager_test.cpp index 4fe6be820..734a3b834 100644 --- a/test/location_locator/source/location_config_manager_test.cpp +++ b/test/location_locator/source/location_config_manager_test.cpp @@ -15,9 +15,12 @@ #include "location_config_manager_test.h" +#include + #include "common_utils.h" #include "constant_definition.h" #include "location_config_manager.h" +#include "location_log.h" using namespace testing::ext; namespace OHOS { @@ -33,6 +36,17 @@ void LocationConfigManagerTest::TearDown() { } +std::string LocationConfigManagerTest::GetLocationSwitchConfigPath() +{ + int userId = 0; + bool ret = CommonUtils::GetCurrentUserId(userId); + if (!ret) { + LBSLOGE(LOCATOR, "GetCurrentUserId failed"); + } + std::string filePath = LOCATION_DIR + SWITCH_CONFIG_NAME + "_" + std::to_string(userId) + ".conf"; + return filePath; +} + HWTEST_F(LocationConfigManagerTest, LocationConfigManagerInitTest001, TestSize.Level1) { GTEST_LOG_(INFO) @@ -61,6 +75,9 @@ HWTEST_F(LocationConfigManagerTest, LocationConfigManagerSwitchStateTest001, Tes LocationConfigManager::GetInstance().SetLocationSwitchState(STATE_UNKNOWN)); EXPECT_EQ(STATE_OPEN, LocationConfigManager::GetInstance().GetLocationSwitchState()); + EXPECT_EQ(true, + LocationConfigManager::GetInstance().IsExistFile(GetLocationSwitchConfigPath())); + remove(GetLocationSwitchConfigPath().c_str()); LBSLOGI(LOCATOR, "[LocationConfigManagerTest] LocationConfigManagerSwitchStateTest001 end"); } @@ -91,6 +108,8 @@ HWTEST_F(LocationConfigManagerTest, LocationConfigManagerPrivacyTypeStateTest001 EXPECT_EQ(ERRCODE_SUCCESS, LocationConfigManager::GetInstance().GetPrivacyTypeState(PRIVACY_TYPE_CORE_LOCATION, isConfirmed)); EXPECT_EQ(false, isConfirmed); + remove(LocationConfigManager::GetInstance().GetPrivacyTypeConfigPath(PRIVACY_TYPE_STARTUP).c_str()); + remove(LocationConfigManager::GetInstance().GetPrivacyTypeConfigPath(PRIVACY_TYPE_CORE_LOCATION).c_str()); LBSLOGI(LOCATOR, "[LocationConfigManagerTest] LocationConfigManagerPrivacyTypeStateTest001 end"); } @@ -106,8 +125,6 @@ HWTEST_F(LocationConfigManagerTest, LocationConfigManagerIsExistFileTest001, Tes std::string configPath = LOCATION_DIR + SWITCH_CONFIG_NAME + "_" + std::to_string(userId) + ".conf"; EXPECT_EQ(false, LocationConfigManager::GetInstance().IsExistFile("/wrongpath" + configPath)); - EXPECT_EQ(true, - LocationConfigManager::GetInstance().IsExistFile(configPath)); LBSLOGI(LOCATOR, "[LocationConfigManagerTest] LocationConfigManagerIsExistFileTest001 end"); } diff --git a/test/location_locator/source/location_without_permission_test.cpp b/test/location_locator/source/location_without_permission_test.cpp index 258dcebcb..c9e9571e3 100644 --- a/test/location_locator/source/location_without_permission_test.cpp +++ b/test/location_locator/source/location_without_permission_test.cpp @@ -49,7 +49,9 @@ void LocationWithoutPermissionTest::TearDown() void LocationWithoutPermissionTest::MockNativePermission() { - const char *perms[] = {ACCESS_BACKGROUND_LOCATION.c_str()}; + const char *perms[] = { + ACCESS_BACKGROUND_LOCATION.c_str(), + }; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, .permsNum = LOCATION_WITHOUT_PERM, @@ -127,10 +129,9 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermission002, Tes EXPECT_NE(nullptr, nmeaCallbackHost); EXPECT_EQ(true, locatorImpl->RegisterNmeaMessageCallback(nmeaCallbackHost->AsObject(), 1000)); EXPECT_EQ(true, locatorImpl->UnregisterNmeaMessageCallback(nmeaCallbackHost->AsObject())); - - EXPECT_EQ(true, locatorImpl->IsLocationPrivacyConfirmed(1)); + EXPECT_EQ(false, locatorImpl->IsLocationPrivacyConfirmed(1)); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->SetLocationPrivacyConfirmStatus(1, true)); - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->FlushCachedGnssLocations()); + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->FlushCachedGnssLocations()); EXPECT_EQ(false, locatorImpl->ProxyUidForFreeze(1000, false)); EXPECT_EQ(false, locatorImpl->ResetAllProxy()); @@ -194,11 +195,11 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9001, T std::unique_ptr requestConfig = std::make_unique(); requestConfig->SetPriority(PRIORITY_ACCURACY); sptr callbackStub = new (std::nothrow) LocatorCallbackStub(); - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->StartLocatingV9(requestConfig, callbackStub)); + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->StartLocatingV9(requestConfig, callbackStub)); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->StopLocatingV9(callbackStub)); std::unique_ptr loc = std::make_unique(); - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->GetCachedLocationV9(loc)); + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->GetCachedLocationV9(loc)); EXPECT_EQ(nullptr, loc); LBSLOGI(LOCATOR, "[LocationWithoutPermissionTest] LocatorWithoutLocationPermissionV9001 end"); } @@ -222,7 +223,8 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9002, T EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->RegisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject())); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->UnregisterNmeaMessageCallbackV9(nmeaCallbackHost->AsObject())); - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->FlushCachedGnssLocationsV9()); + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->FlushCachedGnssLocationsV9()); + EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->ProxyUidForFreezeV9(1000, false)); EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->ResetAllProxyV9()); LBSLOGI(LOCATOR, "[LocationWithoutPermissionTest] LocatorWithoutLocationPermissionV9002 end"); @@ -243,11 +245,11 @@ HWTEST_F(LocationWithoutPermissionTest, LocatorWithoutLocationPermissionV9003, T geofence.radius = 3.0; geofence.expiration = 4.0; fenceRequest->geofence = geofence; - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->AddFenceV9(fenceRequest)); - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->RemoveFenceV9(fenceRequest)); + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->AddFenceV9(fenceRequest)); + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->RemoveFenceV9(fenceRequest)); int size = -1; - EXPECT_EQ(ERRCODE_PERMISSION_DENIED, locatorImpl->GetCachedGnssLocationsSizeV9(size)); + EXPECT_EQ(ERRCODE_SWITCH_OFF, locatorImpl->GetCachedGnssLocationsSizeV9(size)); EXPECT_EQ(0, size); auto cachedLocationsCallbackHost = diff --git a/test/location_locator/source/locator_service_test.cpp b/test/location_locator/source/locator_service_test.cpp index ad7464dd8..dc3160577 100644 --- a/test/location_locator/source/locator_service_test.cpp +++ b/test/location_locator/source/locator_service_test.cpp @@ -1087,8 +1087,8 @@ HWTEST_F(LocatorServiceTest, GetIsoCountryCode001, TestSize.Level1) LBSLOGI(LOCATOR, "[LocatorServiceTest] GetIsoCountryCode001 begin"); MessageParcel reply; auto country = proxy_->GetIsoCountryCode(); - EXPECT_EQ("CN", country->GetCountryCodeStr()); - EXPECT_EQ(COUNTRY_CODE_FROM_LOCALE, country->GetCountryCodeType()); + EXPECT_NE("", country->GetCountryCodeStr()); + EXPECT_NE(-1, country->GetCountryCodeType()); LBSLOGI(LOCATOR, "[LocatorServiceTest] GetIsoCountryCode001 end"); }