From 3611d6eb20df209c8d32774d48e2f1a21ea785b8 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Thu, 17 Apr 2025 10:32:35 +0800 Subject: [PATCH 01/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- .../rust/extension/cloud_server_impl.cpp | 13 ++-- .../service/cloud/sync_manager.cpp | 22 ++++++- .../service/cloud/sync_manager.h | 2 + .../service/test/cloud_data_test.cpp | 63 +++++++++++++++++++ 4 files changed, 92 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/rust/extension/cloud_server_impl.cpp b/services/distributeddataservice/rust/extension/cloud_server_impl.cpp index e5413cff2..089d8c757 100644 --- a/services/distributeddataservice/rust/extension/cloud_server_impl.cpp +++ b/services/distributeddataservice/rust/extension/cloud_server_impl.cpp @@ -337,10 +337,12 @@ int32_t CloudServerImpl::Subscribe(int32_t userId, const std::map(reinterpret_cast(bundle.c_str())), bundle.size(), database, databaseLen); if (status != ERRNO_SUCCESS) { + OhCloudExtVectorFree(database); return DBErr::E_ERROR; } } @@ -554,13 +557,14 @@ int32_t CloudServerImpl::Unsubscribe(int32_t userId, const std::map(std::atoi(it->second.c_str())); if (OhCloudExtVectorPush(relation, &subId, sizeof(uint32_t)) != ERRNO_SUCCESS) { + OhCloudExtVectorFree(relation); return DBErr::E_ERROR; } relationLen += 1; } - auto status = OhCloudExtHashMapInsert(pSubs.get(), - const_cast(reinterpret_cast(bundle.c_str())), bundle.size(), relation, relationLen); - if (status != ERRNO_SUCCESS) { + if (OhCloudExtHashMapInsert(pSubs.get(), const_cast(reinterpret_cast(bundle.c_str())), + bundle.size(), relation, relationLen) != ERRNO_SUCCESS) { + OhCloudExtVectorFree(relation); return DBErr::E_ERROR; } bundles.emplace_back(bundle); @@ -568,7 +572,6 @@ int32_t CloudServerImpl::Unsubscribe(int32_t userId, const std::map serv DBMetaMgr::GetInstance().DelMeta(sub.GetRelationKey(bundles[i]), true); } } - return DBErr::E_OK; + return DBMetaMgr::GetInstance().SaveMeta(sub.GetKey(), sub, true) ? DBErr::E_OK : DBErr::E_ERROR; } std::shared_ptr CloudServerImpl::ConnectAssetLoader(uint32_t tokenId, const DBMeta &dbMeta) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index f949d37c7..958a2f88a 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 = GetValidGeneralCode(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 = GetValidGeneralCode(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(std::move(ConvertGenDetailsCode(result))); } if (result.empty()) { @@ -1037,4 +1037,20 @@ void SyncManager::SaveLastSyncInfo(const QueryKey &queryKey, CloudLastSyncInfo & queryKey.bundleName.c_str(), queryKey.user); } } + +DistributedData::GenDetails SyncManager::ConvertGenDetailsCode(const GenDetails &details) +{ + GenDetails newDetails; + for (const auto &it : details) { + GenProgressDetail detail = it.second; + detail.code = GetValidGeneralCode(detail.code); + newDetails.emplace(std::make_pair(it.first, std::move(detail))); + } + return newDetails; +} + +int32_t SyncManager::GetValidGeneralCode(int32_t code) +{ + return (code >= E_OK && code <= E_BLOCKED_BY_NETWORK_STRATEGY) ? 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 0769c4ea4..df43ddafb 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 GetValidGeneralCode(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 fde1eea08..0c7eb67b9 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -2836,5 +2836,68 @@ 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); +} + +/** +* @tc.name: GetValidGeneralCode +* @tc.desc: Test GetValidGeneralCode function. +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, GetValidGeneralCode, TestSize.Level0) +{ + auto ret = CloudData::SyncManager::GetValidGeneralCode(E_OK); + EXPECT_TRUE(ret == E_OK); + ret = CloudData::SyncManager::GetValidGeneralCode(E_ERROR); + EXPECT_TRUE(ret == E_ERROR); + ret = CloudData::SyncManager::GetValidGeneralCode(E_NETWORK_ERROR); + EXPECT_TRUE(ret == E_NETWORK_ERROR); + ret = CloudData::SyncManager::GetValidGeneralCode(E_CLOUD_DISABLED); + EXPECT_TRUE(ret == E_CLOUD_DISABLED); + ret = CloudData::SyncManager::GetValidGeneralCode(E_LOCKED_BY_OTHERS); + EXPECT_TRUE(ret == E_LOCKED_BY_OTHERS); + ret = CloudData::SyncManager::GetValidGeneralCode(E_RECODE_LIMIT_EXCEEDED); + EXPECT_TRUE(ret == E_RECODE_LIMIT_EXCEEDED); + ret = CloudData::SyncManager::GetValidGeneralCode(E_NO_SPACE_FOR_ASSET); + EXPECT_TRUE(ret == E_NO_SPACE_FOR_ASSET); + ret = CloudData::SyncManager::GetValidGeneralCode(E_BLOCKED_BY_NETWORK_STRATEGY); + EXPECT_TRUE(ret == E_BLOCKED_BY_NETWORK_STRATEGY); + ret = CloudData::SyncManager::GetValidGeneralCode(E_BUSY); + EXPECT_TRUE(ret == E_ERROR); + ret = CloudData::SyncManager::GetValidGeneralCode(E_SYNC_TASK_MERGED); + EXPECT_TRUE(ret == E_ERROR); +} } // namespace DistributedDataTest } // namespace OHOS::Test \ No newline at end of file -- Gitee From 3c63cad379762686085f2e05b829bc0b243b632e Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Tue, 22 Apr 2025 10:32:33 +0800 Subject: [PATCH 02/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- services/distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 958a2f88a..7af1f936a 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -1038,7 +1038,7 @@ void SyncManager::SaveLastSyncInfo(const QueryKey &queryKey, CloudLastSyncInfo & } } -DistributedData::GenDetails SyncManager::ConvertGenDetailsCode(const GenDetails &details) +GenDetails SyncManager::ConvertGenDetailsCode(const GenDetails &details) { GenDetails newDetails; for (const auto &it : details) { -- Gitee From 684dad8d91a25beeddf1fab3f9017589e6addd66 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Tue, 22 Apr 2025 10:32:33 +0800 Subject: [PATCH 03/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- .../service/test/cloud_data_test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 0c7eb67b9..dfc8b1fb5 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -2868,6 +2868,22 @@ HWTEST_F(CloudDataTest, ConvertGenDetailsCode, TestSize.Level0) 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); } /** -- Gitee From 481bf1c7cdaecb1030b664985ad4d5b207348425 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Tue, 22 Apr 2025 10:32:33 +0800 Subject: [PATCH 04/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- services/distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 7af1f936a..6ba646140 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -1051,6 +1051,6 @@ GenDetails SyncManager::ConvertGenDetailsCode(const GenDetails &details) int32_t SyncManager::GetValidGeneralCode(int32_t code) { - return (code >= E_OK && code <= E_BLOCKED_BY_NETWORK_STRATEGY) ? code : E_ERROR; + return (code >= E_OK && code < E_BUSY) ? code : E_ERROR; } } // namespace OHOS::CloudData \ No newline at end of file -- Gitee From 992f78c40d9df0570eed00deaabe0e303c0711cc Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Sun, 27 Apr 2025 10:16:27 +0800 Subject: [PATCH 05/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- .../service/cloud/sync_manager.cpp | 8 ++-- .../service/cloud/sync_manager.h | 2 +- .../service/test/cloud_data_test.cpp | 40 +++++++++---------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 6ba646140..870c52d77 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 = GetValidGeneralCode(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 = GetValidGeneralCode(code); + iter->second.code = ConvertValidGeneralCode(code); iter->second.syncStatus = SyncStatus::FINISHED; SaveLastSyncInfo(key, std::move(iter->second)); iter = val.erase(iter); @@ -1043,13 +1043,13 @@ GenDetails SyncManager::ConvertGenDetailsCode(const GenDetails &details) GenDetails newDetails; for (const auto &it : details) { GenProgressDetail detail = it.second; - detail.code = GetValidGeneralCode(detail.code); + detail.code = ConvertValidGeneralCode(detail.code); newDetails.emplace(std::make_pair(it.first, std::move(detail))); } return newDetails; } -int32_t SyncManager::GetValidGeneralCode(int32_t code) +int32_t SyncManager::ConvertValidGeneralCode(int32_t code) { return (code >= E_OK && code < E_BUSY) ? code : E_ERROR; } diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index df43ddafb..9e4e13cea 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -173,7 +173,7 @@ private: std::pair GetMetaData(const StoreInfo &storeInfo); void AddCompensateSync(const StoreMetaData &meta); static DistributedData::GenDetails ConvertGenDetailsCode(const GenDetails &details); - static int32_t GetValidGeneralCode(int32_t code); + 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 dfc8b1fb5..aa1070cad 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -2850,7 +2850,7 @@ HWTEST_F(CloudDataTest, ConvertGenDetailsCode, TestSize.Level0) detail.progress = GenProgress::SYNC_IN_PROGRESS; detail.code = 100; result.insert(std::make_pair("test", detail)); - auto details = CloudData::SyncManager::ConvertGenDetailsCode(result); + auto details = CloudData::SyncManager::ConvertGenDetailsCode(result); EXPECT_TRUE(details["test"].code == E_ERROR); DistributedData::GenDetails result1; @@ -2858,61 +2858,61 @@ HWTEST_F(CloudDataTest, ConvertGenDetailsCode, TestSize.Level0) detail1.progress = GenProgress::SYNC_IN_PROGRESS; detail1.code = E_ERROR; result1.insert(std::make_pair("test", detail1)); - details = CloudData::SyncManager::ConvertGenDetailsCode(result1); + 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; + detail2.code = E_OK; result2.insert(std::make_pair("test", detail2)); - details = CloudData::SyncManager::ConvertGenDetailsCode(result2); + 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; + detail3.code = E_BLOCKED_BY_NETWORK_STRATEGY; result3.insert(std::make_pair("test", detail3)); - details = CloudData::SyncManager::ConvertGenDetailsCode(result3); + 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; + detail4.code = E_BUSY; result4.insert(std::make_pair("test", detail4)); - details = CloudData::SyncManager::ConvertGenDetailsCode(result4); + details = CloudData::SyncManager::ConvertGenDetailsCode(result4); EXPECT_TRUE(details["test"].code == E_ERROR); } /** -* @tc.name: GetValidGeneralCode -* @tc.desc: Test GetValidGeneralCode function. +* @tc.name: ConvertValidGeneralCode +* @tc.desc: Test ConvertValidGeneralCode function. * @tc.type: FUNC * @tc.require: */ HWTEST_F(CloudDataTest, GetValidGeneralCode, TestSize.Level0) { - auto ret = CloudData::SyncManager::GetValidGeneralCode(E_OK); + auto ret = CloudData::SyncManager::ConvertValidGeneralCode(E_OK); EXPECT_TRUE(ret == E_OK); - ret = CloudData::SyncManager::GetValidGeneralCode(E_ERROR); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_ERROR); EXPECT_TRUE(ret == E_ERROR); - ret = CloudData::SyncManager::GetValidGeneralCode(E_NETWORK_ERROR); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_NETWORK_ERROR); EXPECT_TRUE(ret == E_NETWORK_ERROR); - ret = CloudData::SyncManager::GetValidGeneralCode(E_CLOUD_DISABLED); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_CLOUD_DISABLED); EXPECT_TRUE(ret == E_CLOUD_DISABLED); - ret = CloudData::SyncManager::GetValidGeneralCode(E_LOCKED_BY_OTHERS); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_LOCKED_BY_OTHERS); EXPECT_TRUE(ret == E_LOCKED_BY_OTHERS); - ret = CloudData::SyncManager::GetValidGeneralCode(E_RECODE_LIMIT_EXCEEDED); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_RECODE_LIMIT_EXCEEDED); EXPECT_TRUE(ret == E_RECODE_LIMIT_EXCEEDED); - ret = CloudData::SyncManager::GetValidGeneralCode(E_NO_SPACE_FOR_ASSET); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_NO_SPACE_FOR_ASSET); EXPECT_TRUE(ret == E_NO_SPACE_FOR_ASSET); - ret = CloudData::SyncManager::GetValidGeneralCode(E_BLOCKED_BY_NETWORK_STRATEGY); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_BLOCKED_BY_NETWORK_STRATEGY); EXPECT_TRUE(ret == E_BLOCKED_BY_NETWORK_STRATEGY); - ret = CloudData::SyncManager::GetValidGeneralCode(E_BUSY); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_BUSY); EXPECT_TRUE(ret == E_ERROR); - ret = CloudData::SyncManager::GetValidGeneralCode(E_SYNC_TASK_MERGED); + ret = CloudData::SyncManager::ConvertValidGeneralCode(E_SYNC_TASK_MERGED); EXPECT_TRUE(ret == E_ERROR); } } // namespace DistributedDataTest -- Gitee From a30f260efd7ef5bcb211b68fae203bf7f52271d3 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Sun, 27 Apr 2025 10:16:27 +0800 Subject: [PATCH 06/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- .../framework/test/cloud_test.cpp | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/test/cloud_test.cpp b/services/distributeddataservice/framework/test/cloud_test.cpp index 5179ef017..f8c265aac 100644 --- a/services/distributeddataservice/framework/test/cloud_test.cpp +++ b/services/distributeddataservice/framework/test/cloud_test.cpp @@ -555,8 +555,56 @@ HWTEST_F(CloudEventTest, GetEventId, TestSize.Level0) * @tc.require: * @tc.author: */ -HWTEST_F(ScreenManagerTest, IsLocked, TestSize.Level0) +HWTEST_F(ScreenManagerTest, IsLocked, TestSize.Level1) { ASSERT_FALSE(ScreenManager::GetInstance()->IsLocked()); } + +/** +* @tc.name: Subscribe +* @tc.desc: test Subscribe function +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(ScreenManagerTest, Subscribe, TestSize.Level1) +{ + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->Subscribe(nullptr)); +} + +/** +* @tc.name: Unsubscribe +* @tc.desc: test Unsubscribe function +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(ScreenManagerTest, Unsubscribe, TestSize.Level1) +{ + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->Unsubscribe(nullptr)); +} + +/** +* @tc.name: SubscribeScreenEvent +* @tc.desc: test SubscribeScreenEvent function +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(ScreenManagerTest, SubscribeScreenEvent, TestSize.Level1) +{ + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->SubscribeScreenEvent()); +} + +/** +* @tc.name: UnsubscribeScreenEvent +* @tc.desc: test UnsubscribeScreenEvent function +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(ScreenManagerTest, UnsubscribeScreenEvent, TestSize.Level1) +{ + EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->UnsubscribeScreenEvent()); +} } // namespace OHOS::Test -- Gitee From dce7ee3ce39bb74bead3a62ac9cccd73a10e3045 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Sun, 27 Apr 2025 10:16:27 +0800 Subject: [PATCH 07/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- services/distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 870c52d77..ca1bc5813 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -827,7 +827,7 @@ std::function SyncManager::GetCallback(const Gen { return [this, async, storeInfo, triggerMode, prepareTraceId, user](const GenDetails &result) { if (async != nullptr) { - async(std::move(ConvertGenDetailsCode(result))); + async(ConvertGenDetailsCode(result)); } if (result.empty()) { -- Gitee From 669158f424c1126c6a6d4817f811beda660c638f Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Fri, 30 May 2025 19:48:54 +0800 Subject: [PATCH 08/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- .../framework/test/BUILD.gn | 12 ++++ .../framework/test/cloud_test.cpp | 60 ------------------- .../framework/test/screen_manager_test.cpp | 55 +++++++++++++++++ .../rust/extension/cloud_server_impl.cpp | 13 ++-- 4 files changed, 72 insertions(+), 68 deletions(-) create mode 100644 services/distributeddataservice/framework/test/screen_manager_test.cpp diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index 4417c7c7a..b9e897414 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -332,6 +332,17 @@ 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 = [ + "json:nlohmann_json_static", + ] +} + ############################################################################### group("unittest") { testonly = true @@ -351,6 +362,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 f8c265aac..7c62a4747 100644 --- a/services/distributeddataservice/framework/test/cloud_test.cpp +++ b/services/distributeddataservice/framework/test/cloud_test.cpp @@ -547,64 +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.Level1) -{ - ASSERT_FALSE(ScreenManager::GetInstance()->IsLocked()); -} - -/** -* @tc.name: Subscribe -* @tc.desc: test Subscribe function -* @tc.type: FUNC -* @tc.require: -* @tc.author: -*/ -HWTEST_F(ScreenManagerTest, Subscribe, TestSize.Level1) -{ - EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->Subscribe(nullptr)); -} - -/** -* @tc.name: Unsubscribe -* @tc.desc: test Unsubscribe function -* @tc.type: FUNC -* @tc.require: -* @tc.author: -*/ -HWTEST_F(ScreenManagerTest, Unsubscribe, TestSize.Level1) -{ - EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->Unsubscribe(nullptr)); -} - -/** -* @tc.name: SubscribeScreenEvent -* @tc.desc: test SubscribeScreenEvent function -* @tc.type: FUNC -* @tc.require: -* @tc.author: -*/ -HWTEST_F(ScreenManagerTest, SubscribeScreenEvent, TestSize.Level1) -{ - EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->SubscribeScreenEvent()); -} - -/** -* @tc.name: UnsubscribeScreenEvent -* @tc.desc: test UnsubscribeScreenEvent function -* @tc.type: FUNC -* @tc.require: -* @tc.author: -*/ -HWTEST_F(ScreenManagerTest, UnsubscribeScreenEvent, TestSize.Level1) -{ - EXPECT_NO_FATAL_FAILURE(ScreenManager::GetInstance()->UnsubscribeScreenEvent()); -} } // 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 000000000..631340b02 --- /dev/null +++ b/services/distributeddataservice/framework/test/screen_manager_test.cpp @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 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 "nlohmann/json.hpp" +#include "utils/crypto.h" +#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/rust/extension/cloud_server_impl.cpp b/services/distributeddataservice/rust/extension/cloud_server_impl.cpp index 089d8c757..e5413cff2 100644 --- a/services/distributeddataservice/rust/extension/cloud_server_impl.cpp +++ b/services/distributeddataservice/rust/extension/cloud_server_impl.cpp @@ -337,12 +337,10 @@ int32_t CloudServerImpl::Subscribe(int32_t userId, const std::map(reinterpret_cast(bundle.c_str())), bundle.size(), database, databaseLen); if (status != ERRNO_SUCCESS) { - OhCloudExtVectorFree(database); return DBErr::E_ERROR; } } @@ -557,14 +554,13 @@ int32_t CloudServerImpl::Unsubscribe(int32_t userId, const std::map(std::atoi(it->second.c_str())); if (OhCloudExtVectorPush(relation, &subId, sizeof(uint32_t)) != ERRNO_SUCCESS) { - OhCloudExtVectorFree(relation); return DBErr::E_ERROR; } relationLen += 1; } - if (OhCloudExtHashMapInsert(pSubs.get(), const_cast(reinterpret_cast(bundle.c_str())), - bundle.size(), relation, relationLen) != ERRNO_SUCCESS) { - OhCloudExtVectorFree(relation); + auto status = OhCloudExtHashMapInsert(pSubs.get(), + const_cast(reinterpret_cast(bundle.c_str())), bundle.size(), relation, relationLen); + if (status != ERRNO_SUCCESS) { return DBErr::E_ERROR; } bundles.emplace_back(bundle); @@ -572,6 +568,7 @@ int32_t CloudServerImpl::Unsubscribe(int32_t userId, const std::map serv DBMetaMgr::GetInstance().DelMeta(sub.GetRelationKey(bundles[i]), true); } } - return DBMetaMgr::GetInstance().SaveMeta(sub.GetKey(), sub, true) ? DBErr::E_OK : DBErr::E_ERROR; + return DBErr::E_OK; } std::shared_ptr CloudServerImpl::ConnectAssetLoader(uint32_t tokenId, const DBMeta &dbMeta) -- Gitee From a7bc1dceb35ceef01865dac5ffcc241bfec3fd75 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Fri, 30 May 2025 19:48:54 +0800 Subject: [PATCH 09/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- .../framework/test/screen_manager_test.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/distributeddataservice/framework/test/screen_manager_test.cpp b/services/distributeddataservice/framework/test/screen_manager_test.cpp index 631340b02..132832111 100644 --- a/services/distributeddataservice/framework/test/screen_manager_test.cpp +++ b/services/distributeddataservice/framework/test/screen_manager_test.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2024 Huawei Device Co., Ltd. +* 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 @@ -16,9 +16,6 @@ #define LOG_TAG "ScreenManagerTest" #include - -#include "nlohmann/json.hpp" -#include "utils/crypto.h" #include "screen/screen_manager.h" using namespace testing::ext; -- Gitee From e2bb5e3d692827c1a7fc9dbfb3b82ddd2eef9ad6 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Fri, 30 May 2025 19:48:54 +0800 Subject: [PATCH 10/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- services/distributeddataservice/framework/test/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index b9e897414..bd84cf965 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -362,7 +362,7 @@ group("unittest") { ":FeatureTest", ":GeneralStoreTest", ":MetaDataManagerTest", - "ScreenManagerTest", + ":ScreenManagerTest", ":SerializableTest", ":ServiceMetaDataTest", ":ServiceUtilsTest", -- Gitee From c075d0a82a714eb142c2d84e69ddd0918f1f0e73 Mon Sep 17 00:00:00 2001 From: Jeam_wang Date: Fri, 30 May 2025 19:48:54 +0800 Subject: [PATCH 11/11] =?UTF-8?q?js=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=8C=83=E5=9B=B4=E9=99=90=E5=88=B6=20=E5=8F=8A?= =?UTF-8?q?=E8=B0=83=E7=94=A8rust=E4=B8=ADvector=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeam_wang --- services/distributeddataservice/framework/test/BUILD.gn | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index bd84cf965..27103cfc8 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -337,10 +337,7 @@ ohos_unittest("ScreenManagerTest") { sources = [ "screen_manager_test.cpp" ] configs = [ ":module_private_config" ] deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] - - external_deps = [ - "json:nlohmann_json_static", - ] + external_deps = [ "kv_store:datamgr_common" ] } ############################################################################### -- Gitee