diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index 4417c7c7a3a08a8a1290cb40426b9b65309162ad..27103cfc88e2dc294a9a86b2d29ced7da4da9181 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -332,6 +332,14 @@ ohos_unittest("ServiceMetaDataTest") { ] } +ohos_unittest("ScreenManagerTest") { + module_out_path = module_output_path + sources = [ "screen_manager_test.cpp" ] + configs = [ ":module_private_config" ] + deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] + external_deps = [ "kv_store:datamgr_common" ] +} + ############################################################################### group("unittest") { testonly = true @@ -351,6 +359,7 @@ group("unittest") { ":FeatureTest", ":GeneralStoreTest", ":MetaDataManagerTest", + ":ScreenManagerTest", ":SerializableTest", ":ServiceMetaDataTest", ":ServiceUtilsTest", diff --git a/services/distributeddataservice/framework/test/cloud_test.cpp b/services/distributeddataservice/framework/test/cloud_test.cpp index 5179ef0176e1ec1d57250cbd3ce39694cbc6680e..7c62a47477a4f360225d0e19c81afbcc0091fd38 100644 --- a/services/distributeddataservice/framework/test/cloud_test.cpp +++ b/services/distributeddataservice/framework/test/cloud_test.cpp @@ -547,16 +547,4 @@ HWTEST_F(CloudEventTest, GetEventId, TestSize.Level0) auto ret = event.GetEventId(); EXPECT_EQ(ret, evtId); } - -/** -* @tc.name: IsLocked -* @tc.desc: test IsLocked function -* @tc.type: FUNC -* @tc.require: -* @tc.author: -*/ -HWTEST_F(ScreenManagerTest, IsLocked, TestSize.Level0) -{ - ASSERT_FALSE(ScreenManager::GetInstance()->IsLocked()); -} } // namespace OHOS::Test diff --git a/services/distributeddataservice/framework/test/screen_manager_test.cpp b/services/distributeddataservice/framework/test/screen_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..132832111ade91199535a51a160dede798bbfeb5 --- /dev/null +++ b/services/distributeddataservice/framework/test/screen_manager_test.cpp @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2025 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. +*/ + +#define LOG_TAG "ScreenManagerTest" +#include + +#include "screen/screen_manager.h" + +using namespace testing::ext; +using namespace OHOS::DistributedData; +namespace OHOS::Test { +class ScreenManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void){}; + void SetUp(){}; + void TearDown(){}; +}; + +void ScreenManagerTest::SetUpTestCase() +{ + ScreenManager::GetInstance()->BindExecutor(nullptr); +} + +/** +* @tc.name: IsLocked +* @tc.desc: test IsLocked function +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(ScreenManagerTest, IsLocked, TestSize.Level1) +{ + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->Subscribe(nullptr)); + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->Unsubscribe(nullptr)); + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->SubscribeScreenEvent()); + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->UnsubscribeScreenEvent()); + ASSERT_FALSE(ScreenManager::GetInstance()->IsLocked()); +} +} // namespace OHOS::Test diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index f949d37c7afbf3e85c0babc48bda8d532dbc4dd1..ca1bc5813e3b722f549629d6a6494e27b6c4d9b5 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -402,7 +402,7 @@ void SyncManager::StartCloudSync(const DistributedData::SyncEvent &evt, const St : GetCallback(async, storeInfo, evt.GetTriggerMode(), prepareTraceId, user), syncParam); if (status != E_OK) { if (async) { - detail.code = status; + detail.code = ConvertValidGeneralCode(status); async(std::move(details)); } UpdateFinishSyncInfo({ storeInfo.user, GetAccountId(storeInfo.user), storeInfo.bundleName, @@ -810,7 +810,7 @@ void SyncManager::UpdateFinishSyncInfo(const QueryKey &queryKey, uint64_t syncId iter = val.erase(iter); } else if (iter->first == syncId) { iter->second.finishTime = duration_cast(system_clock::now().time_since_epoch()).count(); - iter->second.code = code; + iter->second.code = ConvertValidGeneralCode(code); iter->second.syncStatus = SyncStatus::FINISHED; SaveLastSyncInfo(key, std::move(iter->second)); iter = val.erase(iter); @@ -827,7 +827,7 @@ std::function SyncManager::GetCallback(const Gen { return [this, async, storeInfo, triggerMode, prepareTraceId, user](const GenDetails &result) { if (async != nullptr) { - async(result); + async(ConvertGenDetailsCode(result)); } if (result.empty()) { @@ -1037,4 +1037,20 @@ void SyncManager::SaveLastSyncInfo(const QueryKey &queryKey, CloudLastSyncInfo & queryKey.bundleName.c_str(), queryKey.user); } } + +GenDetails SyncManager::ConvertGenDetailsCode(const GenDetails &details) +{ + GenDetails newDetails; + for (const auto &it : details) { + GenProgressDetail detail = it.second; + detail.code = ConvertValidGeneralCode(detail.code); + newDetails.emplace(std::make_pair(it.first, std::move(detail))); + } + return newDetails; +} + +int32_t SyncManager::ConvertValidGeneralCode(int32_t code) +{ + return (code >= E_OK && code < E_BUSY) ? code : E_ERROR; +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index 0769c4ea4870cc2048f3c74692b973d843400b98..9e4e13cea20280cb2544cad1cd5b80946dfcc3a6 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -172,6 +172,8 @@ private: const AutoCache::Store &store, Retryer retryer, DistributedData::GenDetails &details); std::pair GetMetaData(const StoreInfo &storeInfo); void AddCompensateSync(const StoreMetaData &meta); + static DistributedData::GenDetails ConvertGenDetailsCode(const GenDetails &details); + static int32_t ConvertValidGeneralCode(int32_t code); static std::atomic genId_; std::shared_ptr executor_; ConcurrentMap actives_; diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index fde1eea08bd49aed9a86aa3ba3278ec02e1a3562..aa1070cad7f9f74596e406746500bcde8c24585a 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -2836,5 +2836,84 @@ HWTEST_F(CloudDataTest, CleanWaterVersion, TestSize.Level1) AccountDelegate::GetInstance()->GetUserByToken(IPCSkeleton::GetCallingTokenID())); EXPECT_TRUE(ret); } + +/** +* @tc.name: ConvertGenDetailsCode +* @tc.desc: Test ConvertGenDetailsCode function. +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, ConvertGenDetailsCode, TestSize.Level0) +{ + DistributedData::GenDetails result; + GenProgressDetail detail; + detail.progress = GenProgress::SYNC_IN_PROGRESS; + detail.code = 100; + result.insert(std::make_pair("test", detail)); + auto details = CloudData::SyncManager::ConvertGenDetailsCode(result); + EXPECT_TRUE(details["test"].code == E_ERROR); + + DistributedData::GenDetails result1; + GenProgressDetail detail1; + detail1.progress = GenProgress::SYNC_IN_PROGRESS; + detail1.code = E_ERROR; + result1.insert(std::make_pair("test", detail1)); + details = CloudData::SyncManager::ConvertGenDetailsCode(result1); + EXPECT_TRUE(details["test"].code == E_ERROR); + + DistributedData::GenDetails result2; + GenProgressDetail detail2; + detail2.progress = GenProgress::SYNC_IN_PROGRESS; + detail2.code = E_OK; + result2.insert(std::make_pair("test", detail2)); + details = CloudData::SyncManager::ConvertGenDetailsCode(result2); + EXPECT_TRUE(details["test"].code == E_OK); + + DistributedData::GenDetails result3; + GenProgressDetail detail3; + detail3.progress = GenProgress::SYNC_IN_PROGRESS; + detail3.code = E_BLOCKED_BY_NETWORK_STRATEGY; + result3.insert(std::make_pair("test", detail3)); + details = CloudData::SyncManager::ConvertGenDetailsCode(result3); + EXPECT_TRUE(details["test"].code == E_BLOCKED_BY_NETWORK_STRATEGY); + + DistributedData::GenDetails result4; + GenProgressDetail detail4; + detail4.progress = GenProgress::SYNC_IN_PROGRESS; + detail4.code = E_BUSY; + result4.insert(std::make_pair("test", detail4)); + details = CloudData::SyncManager::ConvertGenDetailsCode(result4); + EXPECT_TRUE(details["test"].code == E_ERROR); +} + +/** +* @tc.name: ConvertValidGeneralCode +* @tc.desc: Test ConvertValidGeneralCode function. +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, GetValidGeneralCode, TestSize.Level0) +{ + auto ret = CloudData::SyncManager::ConvertValidGeneralCode(E_OK); + EXPECT_TRUE(ret == E_OK); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_ERROR); + EXPECT_TRUE(ret == E_ERROR); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_NETWORK_ERROR); + EXPECT_TRUE(ret == E_NETWORK_ERROR); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_CLOUD_DISABLED); + EXPECT_TRUE(ret == E_CLOUD_DISABLED); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_LOCKED_BY_OTHERS); + EXPECT_TRUE(ret == E_LOCKED_BY_OTHERS); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_RECODE_LIMIT_EXCEEDED); + EXPECT_TRUE(ret == E_RECODE_LIMIT_EXCEEDED); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_NO_SPACE_FOR_ASSET); + EXPECT_TRUE(ret == E_NO_SPACE_FOR_ASSET); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_BLOCKED_BY_NETWORK_STRATEGY); + EXPECT_TRUE(ret == E_BLOCKED_BY_NETWORK_STRATEGY); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_BUSY); + EXPECT_TRUE(ret == E_ERROR); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_SYNC_TASK_MERGED); + EXPECT_TRUE(ret == E_ERROR); +} } // namespace DistributedDataTest } // namespace OHOS::Test \ No newline at end of file