From e78b92e434eef305c09f2417fdb778bc11d435ae Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Wed, 28 May 2025 16:08:42 +0800 Subject: [PATCH 01/22] udmf add acl Signed-off-by: wanghuajian-6 --- .../route_head_handler_impl.cpp | 30 ++++++++++- .../session_manager/route_head_handler_impl.h | 2 +- .../include/metadata/capability_meta_data.h | 4 +- .../include/metadata/store_meta_data.h | 2 + .../service/udmf/store/runtime_store.cpp | 29 ++++++----- .../service/udmf/store/runtime_store.h | 3 +- .../service/udmf/udmf_service_impl.cpp | 50 +++++++++++++++---- .../service/udmf/udmf_service_impl.h | 3 ++ 8 files changed, 95 insertions(+), 28 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index 9437ee8ac..09142bd4d 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -96,7 +96,8 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::GetHeadDataSize(uint32_t &headSize { ZLOGD("begin"); headSize = 0; - if (appId_ == Bootstrap::GetInstance().GetProcessLabel()) { + bool udmfStore = IsUdmfStore(); + if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && !udmfStore) { ZLOGI("meta data permitted"); return DistributedDB::OK; } @@ -123,6 +124,10 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::GetHeadDataSize(uint32_t &headSize ZLOGI("ignore older version device"); return DistributedDB::OK; } + if (udmfStore && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { + ZLOGI("ignore older version device for udmf"); + return DistributedDB::OK; + } if (!session_.IsValid()) { ZLOGI("no valid session to peer device"); return DistributedDB::DB_ERROR; @@ -274,6 +279,19 @@ bool RouteHeadHandlerImpl::ParseHeadDataLen(const uint8_t *data, uint32_t totalL ZLOGI("other type device received. device:%{public}s", Anonymous::Change(device).c_str()); return true; } + + bool flag = false; + bool udmfStore = IsUdmfStore(); + auto peerCap = UpgradeManager::GetInstance().GetCapability(session_.targetDeviceId, flag); + if (!flag) { + ZLOGI("get peer cap failed"); + return false; + } + if (udmfStore && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { + ZLOGI("ignore older version device for udmf"); + return false; + } + RouteHead head = { 0 }; auto ret = UnPackDataHead(data, totalLen, head); headSize = ret ? sizeof(RouteHead) + head.dataLen : 0; @@ -497,4 +515,14 @@ bool RouteHeadHandlerImpl::UnPackAccountId(uint8_t **data, uint32_t leftSize) session_.accountId = std::string(accountId->accountId, accountIdLen); return true; } + +bool RouteHeadHandlerImpl::IsUdmfStore() +{ + if (appId_ == Bootstrap::GetInstance().GetProcessLabel()) { + if (storeId_ != Bootstrap::GetInstance().GetMetaDBName() && storeId_ != "") { + return true; + } + } + return false; +} } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h index 75331a354..87b5e7fdd 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h @@ -92,7 +92,7 @@ private: bool UnPackStoreId(uint8_t **data, uint32_t leftSize); bool UnPackAccountId(uint8_t **data, uint32_t leftSize); std::string ParseStoreId(const std::string &deviceId, const std::string &label); - + bool IsUdmfStore(); std::string userId_; std::string appId_; std::string storeId_; diff --git a/services/distributeddataservice/framework/include/metadata/capability_meta_data.h b/services/distributeddataservice/framework/include/metadata/capability_meta_data.h index 28102100a..1c49339e1 100644 --- a/services/distributeddataservice/framework/include/metadata/capability_meta_data.h +++ b/services/distributeddataservice/framework/include/metadata/capability_meta_data.h @@ -21,9 +21,11 @@ namespace OHOS::DistributedData { class API_EXPORT CapMetaData final : public Serializable { public: // 1->2 add accountId to session - static constexpr int32_t CURRENT_VERSION = 2; + // 2->3 udmf and object add to session + static constexpr int32_t CURRENT_VERSION = 3; static constexpr int32_t INVALID_VERSION = -1; static constexpr int32_t ACCOUNT_VERSION = 2; + static constexpr int32_t UDMF_AND_OBJECT_VERSION = 3; int32_t version = INVALID_VERSION; std::string deviceId = ""; diff --git a/services/distributeddataservice/framework/include/metadata/store_meta_data.h b/services/distributeddataservice/framework/include/metadata/store_meta_data.h index 2d1776341..40e6ca1ae 100644 --- a/services/distributeddataservice/framework/include/metadata/store_meta_data.h +++ b/services/distributeddataservice/framework/include/metadata/store_meta_data.h @@ -69,6 +69,8 @@ struct API_EXPORT StoreMetaData final : public Serializable { STORE_RELATIONAL_END = 19, STORE_OBJECT_BEGIN = 20, STORE_OBJECT_END = 29, + STORE_UDMF_BEGIN = 30, + STORE_UDMF_END = 39, STORE_BUTT = 255 }; diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index 60e59ff40..fa287bff2 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -24,6 +24,7 @@ #include "account/account_delegate.h" #include "metadata/meta_data_manager.h" #include "metadata/appid_meta_data.h" +#include "metadata/store_meta_data.h" #include "device_manager_adapter.h" #include "bootstrap.h" #include "directory/directory_manager.h" @@ -34,6 +35,7 @@ namespace OHOS { namespace UDMF { using namespace RadarReporter; using namespace DistributedDB; +using namespace OHOS::DistributedData; using Anonymous = OHOS::DistributedData::Anonymous; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; constexpr const char *SUMMARY_SUFIX = "#summary"; @@ -462,6 +464,7 @@ bool RuntimeStore::BuildMetaDataParam(DistributedData::StoreMetaData &metaData) } uint32_t token = IPCSkeleton::GetSelfTokenID(); + // uint32_t token = IPCSkeleton::GetCallingTokenID(); const std::string userId = std::to_string(DistributedData::AccountDelegate::GetInstance()->GetUserByToken(token)); metaData.appType = "harmony"; metaData.deviceId = localDeviceId; @@ -475,11 +478,11 @@ bool RuntimeStore::BuildMetaDataParam(DistributedData::StoreMetaData &metaData) metaData.account = DistributedData::AccountDelegate::GetInstance()->GetCurrentAccountId(); metaData.tokenId = token; metaData.securityLevel = DistributedKv::SecurityLevel::S1; - metaData.area = DistributedKv::Area::EL1; + metaData.area = DistributedKv::Area::EL2; metaData.uid = static_cast(getuid()); - metaData.storeType = DistributedKv::KvStoreType::SINGLE_VERSION; + metaData.storeType = StoreMetaData::StoreType::STORE_UDMF_BEGIN; metaData.dataType = DistributedKv::DataType::TYPE_DYNAMICAL; - metaData.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(metaData); + metaData.authType = DistributedKv::AuthType::IDENTICAL_ACCOUNT; return true; } @@ -497,21 +500,24 @@ bool RuntimeStore::SaveMetaData() ZLOGE("QueryForegroundUserId failed."); return false; } - - saveMeta.dataDir.append("/").append(std::to_string(foregroundUserId)); + saveMeta.user = std::to_string(foregroundUserId); + saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); // or use constant value + // saveMeta.dataDir.append("/").append(std::to_string(foregroundUserId));// delete if (!DistributedData::DirectoryManager::GetInstance().CreateDirectory(saveMeta.dataDir)) { - ZLOGE("Create directory error"); + ZLOGE("Create directory error, dataDir: %{public}s.", saveMeta.dataDir.c_str()); // log or not? return false; } - SetDelegateManager(saveMeta.dataDir, saveMeta.appId, saveMeta.user, std::to_string(foregroundUserId)); + SetDelegateManager(saveMeta.dataDir, saveMeta.appId, saveMeta.user); DistributedData::StoreMetaData loadLocal; DistributedData::StoreMetaData syncMeta; if (DistributedData::MetaDataManager::GetInstance().LoadMeta(saveMeta.GetKey(), loadLocal, true) && DistributedData::MetaDataManager::GetInstance().LoadMeta(saveMeta.GetKey(), syncMeta, false)) { - ZLOGD("Meta data is already saved."); - return true; + if (loadLocal == saveMeta && syncMeta == saveMeta) { + ZLOGD("Meta data is already saved."); + return true; + } } auto saved = DistributedData::MetaDataManager::GetInstance().SaveMeta(saveMeta.GetKey(), saveMeta) && @@ -531,10 +537,9 @@ bool RuntimeStore::SaveMetaData() return true; } -void RuntimeStore::SetDelegateManager(const std::string &dataDir, const std::string &appId, const std::string &userId, - const std::string &subUser) +void RuntimeStore::SetDelegateManager(const std::string &dataDir, const std::string &appId, const std::string &userId) { - delegateManager_ = std::make_shared(appId, userId, subUser); + delegateManager_ = std::make_shared(appId, userId); DistributedDB::KvStoreConfig kvStoreConfig { dataDir }; auto status = delegateManager_->SetKvStoreConfig(kvStoreConfig); if (status != DBStatus::OK) { diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.h b/services/distributeddataservice/service/udmf/store/runtime_store.h index 107ac11bc..ef9c37e36 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.h +++ b/services/distributeddataservice/service/udmf/store/runtime_store.h @@ -54,8 +54,7 @@ private: std::shared_ptr delegateManager_ = nullptr; std::shared_ptr kvStore_; std::string storeId_; - void SetDelegateManager(const std::string &dataDir, const std::string &appId, const std::string &userId, - const std::string &subUser); + void SetDelegateManager(const std::string &dataDir, const std::string &appId, const std::string &userId); bool SaveMetaData(); Status GetEntries(const std::string &dataPrefix, std::vector &entries); Status PutEntries(const std::vector &entries); diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index f48bb4953..8f33fef58 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -26,9 +26,11 @@ #include "bundlemgr/bundle_mgr_proxy.h" #include "checker_manager.h" #include "device_manager_adapter.h" +#include "device_matrix.h" #include "iservice_registry.h" #include "lifecycle/lifecycle_manager.h" #include "log_print.h" +#include "metadata/capability_meta_data.h" #include "metadata/store_meta_data.h" #include "metadata/meta_data_manager.h" #include "preprocess_utils.h" @@ -570,14 +572,7 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vector syncDevices; - for (auto const &device : devices) { - if (!DistributedData::DeviceManagerAdapter::GetInstance().IsSameAccount(device)) { - ZLOGW("is diff account. device:%{public}s", DistributedData::Anonymous::Change(device).c_str()); - continue; - } - syncDevices.emplace_back(device); - } + RegisterAsyncProcessInfo(query.key); auto store = StoreCache::GetInstance().GetStore(key.intention); if (store == nullptr) { @@ -599,7 +594,11 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vectorSync(syncDevices, callback) != E_OK) { + StoreMetaData meta = StoreMetaData("0", DistributedData::Bootstrap::GetInstance().GetProcessLabel(), key.intention); + if (IsNeedMetaSync(meta, devices) && !DistributedData::MetaDataManager::GetInstance().Sync(devices, [](auto &results) {}, true)) { + ZLOGW("bundleName:%{public}s, meta sync failed", key.bundleName.c_str()); + } + if (store->Sync(devices, callback) != E_OK) { ZLOGE("Store sync failed:%{public}s", key.intention.c_str()); RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); @@ -823,8 +822,8 @@ int32_t UdmfServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun } for (const auto &storeMeta : metaData) { - if (storeMeta.storeType < StoreMetaData::StoreType::STORE_KV_BEGIN || - storeMeta.storeType > StoreMetaData::StoreType::STORE_KV_END || + if (storeMeta.storeType < StoreMetaData::StoreType::STORE_UDMF_BEGIN || + storeMeta.storeType > StoreMetaData::StoreType::STORE_UDMF_END || storeMeta.appId != DistributedData::Bootstrap::GetInstance().GetProcessLabel()) { continue; } @@ -1143,5 +1142,34 @@ int32_t UdmfServiceImpl::GetDataIfAvailable(const std::string &key, const DataLo dataLoadCallback_.Erase(key); return E_OK; } + +bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vector &uuids) +{ + using namespace OHOS::DistributedData; + bool isAfterMeta = false; + for (const auto &uuid : uuids) { + auto metaData = meta; + metaData.deviceId = uuid; + CapMetaData capMeta; + auto capKey = CapMetaRow::GetKeyFor(uuid); + if (!MetaDataManager::GetInstance().LoadMeta(std::string(capKey.begin(), capKey.end()), capMeta) || + !MetaDataManager::GetInstance().LoadMeta(metaData.GetKey(), metaData)) { + isAfterMeta = true; + break; + } + auto [exist, mask] = DeviceMatrix::GetInstance().GetRemoteMask(uuid); + if ((mask & DeviceMatrix::META_STORE_MASK) == DeviceMatrix::META_STORE_MASK) { + isAfterMeta = true; + break; + } + auto [existLocal, localMask] = DeviceMatrix::GetInstance().GetMask(uuid); + if ((localMask & DeviceMatrix::META_STORE_MASK) == DeviceMatrix::META_STORE_MASK) { + isAfterMeta = true; + break; + } + } + return isAfterMeta; +} + } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.h b/services/distributeddataservice/service/udmf/udmf_service_impl.h index 09127a317..e70b7e0c6 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.h +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.h @@ -19,6 +19,7 @@ #include "store_cache.h" #include "udmf_service_stub.h" #include "kv_store_delegate_manager.h" +#include "metadata/store_meta_data.h" #include "checker_manager.h" #include "udmf_notifier_proxy.h" namespace OHOS { @@ -76,6 +77,8 @@ private: bool IsFileMangerIntention(const std::string &intention); std::string FindIntentionMap(const Intention &queryintention); bool IsValidOptionsNonDrag(UnifiedKey &key, const std::string &intention); + bool IsNeedMetaSync(const DistributedData::StoreMetaData &meta, const std::vector &uuids); + class Factory { public: Factory(); -- Gitee From 25a5d82b5086aa07654eb333f421d4408ca26f7e Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Thu, 29 May 2025 19:34:37 +0800 Subject: [PATCH 02/22] udmf add acl Signed-off-by: wanghuajian-6 --- .../app/src/session_manager/route_head_handler_impl.cpp | 4 ++-- .../framework/directory/directory_manager.cpp | 5 ++++- services/distributeddataservice/service/udmf/BUILD.gn | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index 09142bd4d..b013ea5e9 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -282,7 +282,7 @@ bool RouteHeadHandlerImpl::ParseHeadDataLen(const uint8_t *data, uint32_t totalL bool flag = false; bool udmfStore = IsUdmfStore(); - auto peerCap = UpgradeManager::GetInstance().GetCapability(session_.targetDeviceId, flag); + auto peerCap = UpgradeManager::GetInstance().GetCapability(device, flag); if (!flag) { ZLOGI("get peer cap failed"); return false; @@ -519,7 +519,7 @@ bool RouteHeadHandlerImpl::UnPackAccountId(uint8_t **data, uint32_t leftSize) bool RouteHeadHandlerImpl::IsUdmfStore() { if (appId_ == Bootstrap::GetInstance().GetProcessLabel()) { - if (storeId_ != Bootstrap::GetInstance().GetMetaDBName() && storeId_ != "") { + if (storeId_ != Bootstrap::GetInstance().GetMetaDBName() && storeId_ != "distributedObject_") { return true; } } diff --git a/services/distributeddataservice/framework/directory/directory_manager.cpp b/services/distributeddataservice/framework/directory/directory_manager.cpp index 9deb434e7..4b1786a56 100644 --- a/services/distributeddataservice/framework/directory/directory_manager.cpp +++ b/services/distributeddataservice/framework/directory/directory_manager.cpp @@ -181,7 +181,9 @@ std::string DirectoryManager::GetArea(const StoreMetaData &metaData) const std::string DirectoryManager::GetUserId(const StoreMetaData &metaData) const { auto type = AccessTokenKit::GetTokenTypeFlag(metaData.tokenId); - if ((type == TOKEN_NATIVE || type == TOKEN_SHELL) && (metaData.user == StoreMetaData::ROOT_USER)) { + if ((type == TOKEN_NATIVE || type == TOKEN_SHELL) && (metaData.user == StoreMetaData::ROOT_USER) && + (metaData.storeType < StoreMetaData::StoreType::STORE_UDMF_BEGIN || + metaData.storeType >= StoreMetaData::StoreType::STORE_UDMF_END)) { return "public"; } return metaData.user; @@ -288,6 +290,7 @@ bool DirectoryManager::CreateDirectory(const std::string &path) const if (access(subPath.c_str(), F_OK) != 0) { if (mkdir(subPath.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) != 0) { + ZLOGE("mkdir error:%{public}d", errno); return false; } } diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index 3b81c5f3f..b73cd4796 100644 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -21,6 +21,7 @@ config("module_public_config") { "${data_service_path}/framework/include/dfx", "${data_service_path}/adapter/include/communicator", "${data_service_path}/adapter/include/account", + "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/lifecycle", "${data_service_path}/service/udmf/permission", "${data_service_path}/service/udmf/preprocess", -- Gitee From efa99a9c4a85721dea28cbaff814d4122f25d5d1 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sun, 1 Jun 2025 15:40:22 +0800 Subject: [PATCH 03/22] udmf add acl Signed-off-by: wanghuajian-6 --- services/distributeddataservice/service/test/BUILD.gn | 6 ++++++ .../service/test/fuzztest/udmfservice_fuzzer/BUILD.gn | 2 ++ 2 files changed, 8 insertions(+) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index c20ecdbfe..20f0f0722 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -883,6 +883,7 @@ ohos_unittest("UdmfRunTimeStoreTest") { "${data_service_path}/adapter/include/communicator", "${data_service_path}/app/src", "${data_service_path}/service/kvdb", + "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf/preprocess", @@ -1158,6 +1159,7 @@ ohos_unittest("UdmfServiceImplTest") { ] include_dirs = [ + ${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/preprocess", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", @@ -1199,6 +1201,7 @@ ohos_unittest("UdmfServiceStubTest") { sources = [ "udmf_service_stub_test.cpp" ] include_dirs = [ + "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/preprocess", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", @@ -1244,6 +1247,7 @@ ohos_unittest("UdmfServiceStubMockTest") { "${data_service_path}/framework/feature/feature_system.cpp", "${data_service_path}/framework/metadata/appid_meta_data.cpp", "${data_service_path}/framework/metadata/auto_launch_meta_data.cpp", + "${data_service_path}/framework/metadata/capability_meta_data.cpp", "${data_service_path}/framework/metadata/capability_range.cpp", "${data_service_path}/framework/metadata/meta_data_manager.cpp", "${data_service_path}/framework/metadata/secret_key_meta_data.cpp", @@ -1272,6 +1276,7 @@ ohos_unittest("UdmfServiceStubMockTest") { ] include_dirs = [ + "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", "${data_service_path}/framework/include", @@ -1360,6 +1365,7 @@ ohos_unittest("UdmfPreProcessUtilsMockTest") { ] include_dirs = [ + "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/preprocess", "${data_service_path}/service/test/mock", "${data_service_path}/service/udmf/store", diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn index bd9b426a6..b2cd385f1 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn @@ -21,6 +21,7 @@ ohos_fuzztest("UdmfServiceFuzzTest") { include_dirs = [ "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/lifecycle", "${data_service_path}/service/udmf/permission", "${data_service_path}/service/udmf/preprocess", @@ -45,6 +46,7 @@ ohos_fuzztest("UdmfServiceFuzzTest") { "${data_service_path}/adapter/communicator:distributeddata_communicator", "${data_service_path}/framework:distributeddatasvcfwk", "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", "${data_service_path}/service/udmf:udmf_server", ] -- Gitee From 150f46b75663657af09abbca2d9577cf29e340fc Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Mon, 2 Jun 2025 16:14:32 +0800 Subject: [PATCH 04/22] udmf add acl Signed-off-by: wanghuajian-6 --- .../distributeddataservice/service/test/BUILD.gn | 2 +- .../service/udmf/udmf_service_impl.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 20f0f0722..e3326bb66 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1159,7 +1159,7 @@ ohos_unittest("UdmfServiceImplTest") { ] include_dirs = [ - ${data_service_path}/service/matrix/include", + "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/preprocess", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index 8f33fef58..2352648ae 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -47,6 +47,7 @@ namespace OHOS { namespace UDMF { using namespace Security::AccessToken; using namespace OHOS::DistributedHardware; +using namespace OHOS::DistributedData; using FeatureSystem = DistributedData::FeatureSystem; using UdmfBehaviourMsg = OHOS::DistributedDataDfx::UdmfBehaviourMsg; using Reporter = OHOS::DistributedDataDfx::Reporter; @@ -594,8 +595,9 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vectorGetUserByToken(IPCSkeleton::GetCallingFullTokenID()); + StoreMetaData meta = StoreMetaData(std::to_string(userId), Bootstrap::GetInstance().GetProcessLabel(), key.intention); + if (IsNeedMetaSync(meta, devices) && !MetaDataManager::GetInstance().Sync(devices, [](auto &results) {}, true)) { ZLOGW("bundleName:%{public}s, meta sync failed", key.bundleName.c_str()); } if (store->Sync(devices, callback) != E_OK) { @@ -824,7 +826,7 @@ int32_t UdmfServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun for (const auto &storeMeta : metaData) { if (storeMeta.storeType < StoreMetaData::StoreType::STORE_UDMF_BEGIN || storeMeta.storeType > StoreMetaData::StoreType::STORE_UDMF_END || - storeMeta.appId != DistributedData::Bootstrap::GetInstance().GetProcessLabel()) { + storeMeta.appId != Bootstrap::GetInstance().GetProcessLabel()) { continue; } auto identifierTag = DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier("", storeMeta.appId, @@ -834,11 +836,10 @@ int32_t UdmfServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun } auto store = StoreCache::GetInstance().GetStore(storeMeta.storeId); if (store == nullptr) { - ZLOGE("GetStore fail, storeId:%{public}s", DistributedData::Anonymous::Change(storeMeta.storeId).c_str()); + ZLOGE("GetStore fail, storeId:%{public}s", Anonymous::Change(storeMeta.storeId).c_str()); continue; } - ZLOGI("storeId:%{public}s,appId:%{public}s,user:%{public}s", - DistributedData::Anonymous::Change(storeMeta.storeId).c_str(), + ZLOGI("storeId:%{public}s,appId:%{public}s,user:%{public}s", Anonymous::Change(storeMeta.storeId).c_str(), storeMeta.appId.c_str(), storeMeta.user.c_str()); return E_OK; } -- Gitee From 4ee15f9ecedd046c2752404a9048f4cd2760a3ae Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Mon, 2 Jun 2025 18:35:47 +0800 Subject: [PATCH 05/22] udmf add acl Signed-off-by: wanghuajian-6 --- .../route_head_handler_impl.cpp | 12 ++++-- .../test/unittest/session_manager_test.cpp | 38 +++++++++++++++++++ .../service/udmf/store/runtime_store.cpp | 2 - .../service/udmf/udmf_service_impl.cpp | 2 +- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index b013ea5e9..f455e11eb 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -39,6 +39,7 @@ using DmAdapter = DistributedData::DeviceManagerAdapter; using DBManager = DistributedDB::KvStoreDelegateManager; constexpr const int ALIGN_WIDTH = 8; constexpr const char *DEFAULT_USERID = "0"; +constexpr static const char *UDMF_DRAG_STORE = "drag"; std::shared_ptr RouteHeadHandlerImpl::Create(const ExtendInfo &info) { auto handler = std::make_shared(info); @@ -73,6 +74,11 @@ void RouteHeadHandlerImpl::Init() userId_ = DEFAULT_USERID; } } + if (IsUdmfStore()) { + int foregroundUserId = 0; + AccountDelegate::GetInstance()->QueryForegroundUserId(foregroundUserId); + userId_ = std::to_string(foregroundUserId); + } SessionPoint localPoint { DmAdapter::GetInstance().GetLocalDevice().uuid, static_cast(atoi(userId_.c_str())), appId_, storeId_, AccountDelegate::GetInstance()->GetCurrentAccountId() }; @@ -518,10 +524,8 @@ bool RouteHeadHandlerImpl::UnPackAccountId(uint8_t **data, uint32_t leftSize) bool RouteHeadHandlerImpl::IsUdmfStore() { - if (appId_ == Bootstrap::GetInstance().GetProcessLabel()) { - if (storeId_ != Bootstrap::GetInstance().GetMetaDBName() && storeId_ != "distributedObject_") { - return true; - } + if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ == UDMF_DRAG_STORE) { + return true; } return false; } diff --git a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp index a6452ce4d..d95efa56f 100644 --- a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp @@ -432,6 +432,44 @@ HWTEST_F(SessionManagerTest, GetHeadDataSize_Test4, TestSize.Level1) status = sendHandler->FillHeadData(data.get(), routeHeadSize, routeHeadSize); EXPECT_EQ(status, DistributedDB::DB_ERROR); } + +/** + * @tc.name: PackAndUnPack05 + * @tc.desc: test get udmf store + * @tc.type: FUNC + * @tc.require: + * @tc.author: illybyy + */ +HWTEST_F(SessionManagerTest, PackAndUnPack05, TestSize.Level1) +{ + const DistributedDB::ExtendInfo info = { + .appId = "distributeddata", .storeId = "drag", .userId = "100", .dstTarget = PEER_DEVICE_ID + }; + auto sendHandler = RouteHeadHandlerImpl::Create(info); + ASSERT_NE(sendHandler, nullptr); + + + CapMetaData capMetaData; + capMetaData.version = CapMetaData::INVALID_VERSION; + + auto peerCapMetaKey = CapMetaRow::GetKeyFor(PEER_DEVICE_ID); + MetaDataManager::GetInstance().SaveMeta({ peerCapMetaKey.begin(), peerCapMetaKey.end() }, capMetaData); + + + uint32_t routeHeadSize = 0; + sendHandler->GetHeadDataSize(routeHeadSize); + ASSERT_NE(routeHeadSize, 0); + std::unique_ptr data = std::make_unique(routeHeadSize); + sendHandler->FillHeadData(data.get(), routeHeadSize, routeHeadSize); + + std::vector users; + auto recvHandler = RouteHeadHandlerImpl::Create({}); + ASSERT_NE(recvHandler, nullptr); + uint32_t parseSize = 0; + std::string device = "from_device"; + recvHandler->ParseHeadDataLen(data.get(), routeHeadSize, parseSize, device); + EXPECT_EQ(routeHeadSize, parseSize); +} /** * @tc.name: ParseHeadDataUserTest001 * @tc.desc: test parse null data. diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index fa287bff2..0c8e85d11 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -464,7 +464,6 @@ bool RuntimeStore::BuildMetaDataParam(DistributedData::StoreMetaData &metaData) } uint32_t token = IPCSkeleton::GetSelfTokenID(); - // uint32_t token = IPCSkeleton::GetCallingTokenID(); const std::string userId = std::to_string(DistributedData::AccountDelegate::GetInstance()->GetUserByToken(token)); metaData.appType = "harmony"; metaData.deviceId = localDeviceId; @@ -502,7 +501,6 @@ bool RuntimeStore::SaveMetaData() } saveMeta.user = std::to_string(foregroundUserId); saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); // or use constant value - // saveMeta.dataDir.append("/").append(std::to_string(foregroundUserId));// delete if (!DistributedData::DirectoryManager::GetInstance().CreateDirectory(saveMeta.dataDir)) { ZLOGE("Create directory error, dataDir: %{public}s.", saveMeta.dataDir.c_str()); // log or not? return false; diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index 2352648ae..7e5464cc4 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -597,7 +597,7 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vectorGetUserByToken(IPCSkeleton::GetCallingFullTokenID()); StoreMetaData meta = StoreMetaData(std::to_string(userId), Bootstrap::GetInstance().GetProcessLabel(), key.intention); - if (IsNeedMetaSync(meta, devices) && !MetaDataManager::GetInstance().Sync(devices, [](auto &results) {}, true)) { + if (IsNeedMetaSync(meta, devices) && !MetaDataManager::GetInstance().Sync(devices, [](auto &results) {})) { ZLOGW("bundleName:%{public}s, meta sync failed", key.bundleName.c_str()); } if (store->Sync(devices, callback) != E_OK) { -- Gitee From 870c2062f08664de7a48acb861c2666d30d4a0d6 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Wed, 4 Jun 2025 16:13:46 +0800 Subject: [PATCH 06/22] add testcase Signed-off-by: wanghuajian-6 --- .../route_head_handler_impl.cpp | 2 +- .../distributeddataservice/app/test/BUILD.gn | 38 ++++++++ .../unittest/route_head_handler_impl_test.cpp | 94 +++++++++++++++++++ .../service/udmf/udmf_service_impl.cpp | 5 +- .../service/udmf/udmf_service_impl.h | 2 +- 5 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index f455e11eb..31fa29568 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -39,7 +39,7 @@ using DmAdapter = DistributedData::DeviceManagerAdapter; using DBManager = DistributedDB::KvStoreDelegateManager; constexpr const int ALIGN_WIDTH = 8; constexpr const char *DEFAULT_USERID = "0"; -constexpr static const char *UDMF_DRAG_STORE = "drag"; +constexpr const char *UDMF_DRAG_STORE = "drag"; std::shared_ptr RouteHeadHandlerImpl::Create(const ExtendInfo &info) { auto handler = std::make_shared(info); diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index bfb70673a..20c89c315 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -368,6 +368,43 @@ ohos_unittest("UpgradeManagerTest") { part_name = "datamgr_service" } +ohos_unittest("RouteHeadHandlerImplTest") { + module_out_path = module_output_path + + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + ] + + include_dirs = [ + "${data_service_path}/app/src/session_manager", + "${data_service_path}/app/test/mock/capability", + "${data_service_path}/framework/include", + "${data_service_path}/adapter/include", + ] + + sources = [ + "${data_service_path}/app/test/mock/capability/metadata/meta_data_manager.cpp", + "${data_service_path}/app/test/mock/capability/device_manager_adapter.cpp", + "${data_service_path}/app/src/session_manager/upgrade_manager.cpp", + "${data_service_path}/framework/metadata/capability_meta_data.cpp", + "${data_service_path}/framework/serializable/serializable.cpp", + "${data_service_path}/framework/utils/anonymous.cpp", + "${data_service_path}/framework/utils/constant.cpp", + "${data_service_path}/app/test/unittest/upgrade_manager_test.cpp", + ] + + external_deps = [ + "c_utils:utils", + "googletest:gtest_main", + "hilog:libhilog", + "cJSON:cjson", + "kv_store:distributeddata_inner", + ] + + part_name = "datamgr_service" +} + ############################################################################### group("unittest") { @@ -380,5 +417,6 @@ group("unittest") { ":KvStoreDataServiceTest", ":SessionManagerTest", ":UpgradeManagerTest", + ":RouteHeadHandlerImplTest", ] } \ No newline at end of file diff --git a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp new file mode 100644 index 000000000..baed04172 --- /dev/null +++ b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp @@ -0,0 +1,94 @@ +/* + * 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. + */ + +#include "route_head_handler_impl.h" + +#include "upgrade_manager.h" + +#include + +#include "device_manager_adapter.h" +#include "metadata/meta_data_manager.h" +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::DistributedData; +using namespace OHOS::DistributedKv; +using namespace DistributedDB; + +static constexpr size_t THREAD_MIN = 0; +static constexpr size_t THREAD_MAX = 2; +static constexpr const char* REMOTE_DEVICE = "0123456789ABCDEF"; + +class RouteHeadHandlerImplTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; + + static std::shared_ptr executors_; + static std::string localDevice_; +}; +static inline std::shared_ptr deviceManagerAdapterMock = nullptr; +std::shared_ptr RouteHeadHandlerImplTest::executors_; +std::string RouteHeadHandlerImplTest::localDevice_; + +void RouteHeadHandlerImplTest::SetUpTestCase(void) +{ + localDevice_ = DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid; + executors_ = std::make_shared(THREAD_MAX, THREAD_MIN); + MetaDataManager::GetInstance().Init(executors_); + UpgradeManager::GetInstance().Init(executors_); + deviceManagerAdapterMock = std::make_shared(); + BDeviceManagerAdapter::deviceManagerAdapter = deviceManagerAdapterMock; + sleep(1); +} + +/** +* @tc.name: GetHeadDataSize_Test1 +* @tc.desc: get headSize for udmf store +* @tc.type: FUNC +*/ +HWTEST_F(RouteHeadHandlerImplTest, GetHeadDataSize_Test1, TestSize.Level0) +{ + DeviceInfo deviceInfo; + deviceInfo.osType = OH_OS_TYPE; + EXPECT_CALL(*deviceManagerAdapterMock, IsOHOSType(_)).WillRepeatedly(Return(true)); + EXPECT_CALL(*deviceManagerAdapterMock, GetDeviceInfo(_)).WillRepeatedly(Return(deviceInfo)); + + const DistributedDB::ExtendInfo info = { + .appId = "otherAppId", .storeId = "test_store", .userId = "100", .dstTarget = REMOTE_DEVICE + }; + auto sendHandler = RouteHeadHandlerImpl::Create(info); + ASSERT_NE(sendHandler, nullptr); + + CapMetaData capMetaData; + capMetaData.version = CapMetaData::CURRENT_VERSION; + capMetaData.deviceId = REMOTE_DEVICE; + auto capKey = CapMetaRow::GetKeyFor(REMOTE_DEVICE); + (void)MetaDataManager::GetInstance().SaveMeta({ capKey.begin(), capKey.end() }, capMetaData); + + bool result = false; + auto capMeta = UpgradeManager::GetInstance().GetCapability(REMOTE_DEVICE, result); + ASSERT_EQ(result, true); + ASSERT_EQ(capMeta.version, capMetaData.version); + ASSERT_EQ(capMeta.deviceId, REMOTE_DEVICE); + + uint32_t headSize = 0; + EXPECT_EQ(sendHandler->GetHeadDataSize(headSize), DBStatus::OK); + EXPECT_NE(headSize, 0); + +} diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index 7e5464cc4..e4ed742bd 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -1144,12 +1144,13 @@ int32_t UdmfServiceImpl::GetDataIfAvailable(const std::string &key, const DataLo return E_OK; } -bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vector &uuids) +bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vector &devices) { using namespace OHOS::DistributedData; bool isAfterMeta = false; - for (const auto &uuid : uuids) { + for (const auto &device : devices) { auto metaData = meta; + auto uuid = DeviceManagerAdapter::GetInstance().ToUUID(device); metaData.deviceId = uuid; CapMetaData capMeta; auto capKey = CapMetaRow::GetKeyFor(uuid); diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.h b/services/distributeddataservice/service/udmf/udmf_service_impl.h index e70b7e0c6..092f1ba57 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.h +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.h @@ -77,7 +77,7 @@ private: bool IsFileMangerIntention(const std::string &intention); std::string FindIntentionMap(const Intention &queryintention); bool IsValidOptionsNonDrag(UnifiedKey &key, const std::string &intention); - bool IsNeedMetaSync(const DistributedData::StoreMetaData &meta, const std::vector &uuids); + bool IsNeedMetaSync(const DistributedData::StoreMetaData &meta, const std::vector &devices); class Factory { public: -- Gitee From 2fe4173dac63968202886cd85a995b8bc5543bf2 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Wed, 4 Jun 2025 16:23:06 +0800 Subject: [PATCH 07/22] add testcase Signed-off-by: wanghuajian-6 --- .../src/session_manager/route_head_handler_impl.cpp | 5 +---- services/distributeddataservice/service/udmf/BUILD.gn | 10 +--------- .../service/udmf/store/runtime_store.cpp | 4 ++-- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index 31fa29568..3155e4351 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -524,9 +524,6 @@ bool RouteHeadHandlerImpl::UnPackAccountId(uint8_t **data, uint32_t leftSize) bool RouteHeadHandlerImpl::IsUdmfStore() { - if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ == UDMF_DRAG_STORE) { - return true; - } - return false; + return (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ == UDMF_DRAG_STORE) } } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index b73cd4796..d00564cf6 100644 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -17,8 +17,6 @@ config("module_public_config") { visibility = [ ":*" ] include_dirs = [ - "${data_service_path}/framework/include", - "${data_service_path}/framework/include/dfx", "${data_service_path}/adapter/include/communicator", "${data_service_path}/adapter/include/account", "${data_service_path}/service/matrix/include", @@ -29,13 +27,7 @@ config("module_public_config") { "${data_service_path}/service/udmf/utd", "${data_service_path}/service/udmf", "${data_service_path}/service/bootstrap/include", - "${kv_store_path}/interfaces/innerkits/distributeddata/include", - "${kv_store_path}/framework/libs/distributeddb/interfaces/include", - "${kv_store_common_path}", - "${udmf_path}/framework/common", - "${udmf_path}/interfaces/innerkits/common", - "${udmf_path}/interfaces/innerkits/data", - "${data_service_path}/adapter/account/src", + ] } diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index 0c8e85d11..03705eeca 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -500,9 +500,9 @@ bool RuntimeStore::SaveMetaData() return false; } saveMeta.user = std::to_string(foregroundUserId); - saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); // or use constant value + saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); if (!DistributedData::DirectoryManager::GetInstance().CreateDirectory(saveMeta.dataDir)) { - ZLOGE("Create directory error, dataDir: %{public}s.", saveMeta.dataDir.c_str()); // log or not? + ZLOGE("Create directory error, dataDir: %{public}s.", Anonymous::Change(saveMeta.dataDir).c_str()); return false; } -- Gitee From 1c82aaf4dadd3a4d50d6e54ce50eec5b4cba66d0 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Wed, 4 Jun 2025 16:27:52 +0800 Subject: [PATCH 08/22] fix confilct Signed-off-by: wanghuajian-6 --- services/distributeddataservice/service/udmf/BUILD.gn | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index 1e286d91e..aa7c6d719 100644 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -17,8 +17,6 @@ config("module_public_config") { visibility = [ ":*" ] include_dirs = [ - "${data_service_path}/framework/include", - "${data_service_path}/framework/include/dfx", "${data_service_path}/adapter/include/communicator", "${data_service_path}/adapter/include/account", "${data_service_path}/service/matrix/include", @@ -29,13 +27,7 @@ config("module_public_config") { "${data_service_path}/service/udmf/utd", "${data_service_path}/service/udmf", "${data_service_path}/service/bootstrap/include", - "${kv_store_path}/interfaces/innerkits/distributeddata/include", - "${kv_store_path}/framework/libs/distributeddb/interfaces/include", - "${kv_store_common_path}", - "${udmf_path}/framework/common", - "${udmf_path}/interfaces/innerkits/common", - "${udmf_path}/interfaces/innerkits/data", - "${data_service_path}/adapter/account/src", + ] } -- Gitee From 2959659cfa94c0a136be0289578874fd0822f761 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Wed, 4 Jun 2025 16:29:05 +0800 Subject: [PATCH 09/22] fix confilct Signed-off-by: wanghuajian-6 --- services/distributeddataservice/service/udmf/BUILD.gn | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index aa7c6d719..6180f01b6 100644 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -18,7 +18,6 @@ config("module_public_config") { include_dirs = [ "${data_service_path}/adapter/include/communicator", - "${data_service_path}/adapter/include/account", "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/lifecycle", "${data_service_path}/service/udmf/permission", @@ -27,7 +26,6 @@ config("module_public_config") { "${data_service_path}/service/udmf/utd", "${data_service_path}/service/udmf", "${data_service_path}/service/bootstrap/include", - ] } -- Gitee From c55798d7283984c251c846f95c19fcc074bd2c6c Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Thu, 5 Jun 2025 16:42:10 +0800 Subject: [PATCH 10/22] add test case Signed-off-by: wanghuajian-6 --- .../route_head_handler_impl.cpp | 2 +- .../service/test/BUILD.gn | 4 ++ .../service/test/udmf_service_impl_test.cpp | 47 +++++++++++++++++-- .../service/udmf/udmf_service_impl.cpp | 1 - 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index 3155e4351..30c770e8b 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -524,6 +524,6 @@ bool RouteHeadHandlerImpl::UnPackAccountId(uint8_t **data, uint32_t leftSize) bool RouteHeadHandlerImpl::IsUdmfStore() { - return (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ == UDMF_DRAG_STORE) + return (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ == UDMF_DRAG_STORE); } } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index e3e240165..4dbdfa8fe 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1152,6 +1152,7 @@ ohos_unittest("UdmfServiceImplTest") { "${data_service_path}/service/udmf", "${data_service_path}/framework/include", "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/test/mock", ] cflags = [ @@ -1162,6 +1163,7 @@ ohos_unittest("UdmfServiceImplTest") { deps = [ "${data_service_path}/service:distributeddatasvc", "${data_service_path}/service/udmf:udmf_server", + "mock:distributeddata_mock_static", ] external_deps = [ @@ -1172,6 +1174,8 @@ ohos_unittest("UdmfServiceImplTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "device_manager:devicemanagersdk", + "googletest:gmock_main", + "googletest:gtest_main", "googletest:gtest_main", "hilog:libhilog", "cJSON:cjson", diff --git a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp index d93a55905..a553a863e 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp @@ -18,18 +18,41 @@ #include "gtest/gtest.h" #include "error_code.h" #include "text.h" - +#include "mock/access_token_mock.h" +#include "mock/meta_data_manager_mock.h" using namespace OHOS::DistributedData; +using namespace OHOS::Security::AccessToken; namespace OHOS::UDMF { using namespace testing::ext; class UdmfServiceImplTest : public testing::Test { public: - static void SetUpTestCase(void) {} - static void TearDownTestCase(void) {} + static void SetUpTestCase(void); + static void TearDownTestCase(void); + static inline std::shared_ptr accTokenMock = nullptr; + static inline std::shared_ptr metaDataManagerMock = nullptr; + static inline std::shared_ptr> metaDataMock = nullptr; void SetUp() {} void TearDown() {} }; +void UdmfServiceImplTest::SetUpTestCase() +{ + accTokenMock = std::make_shared(); + BAccessTokenKit::accessTokenkit = accTokenMock; + metaDataManagerMock = std::make_shared(); + BMetaDataManager::metaDataManager = metaDataManagerMock; + metaDataMock = std::make_shared>(); + BMetaData::metaDataManager = metaDataMock; +} +void UdmfServiceImplTest::TearDownTestCase(void) +{ + accTokenMock = nullptr; + BAccessTokenKit::accessTokenkit = nullptr; + metaDataManagerMock = nullptr; + BMetaDataManager::metaDataManager = nullptr; + metaDataMock = nullptr; + BMetaData::metaDataManager = nullptr; +} /** * @tc.name: SaveData001 * @tc.desc: Abnormal test of SaveData, unifiedData is invalid @@ -240,4 +263,22 @@ HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level1) int recordSize = 2; EXPECT_EQ(data.GetRecords().size(), recordSize); } + +/** +* @tc.name: IsNeedMetaSyncTest001 +* @tc.desc: IsNeedMetaSync test +* @tc.type: FUNC +*/ +HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest001, TestSize.Level0) +{ + UdmfServiceImpl udmfServiceImpl; + StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); + std::vector devices = {"remote_device"}; + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(true)) + .WillRepeatedly(testing::Return(true)); + auto isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, true); +} }; // namespace UDMF \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index e4ed742bd..ea248eb58 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -1172,6 +1172,5 @@ bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vecto } return isAfterMeta; } - } // namespace UDMF } // namespace OHOS \ No newline at end of file -- Gitee From 37aaaa217d090338f865a6aa035d5dbfca476936 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sat, 7 Jun 2025 11:58:12 +0800 Subject: [PATCH 11/22] add test case Signed-off-by: wanghuajian-6 --- .../route_head_handler_impl.cpp | 4 +- .../distributeddataservice/app/test/BUILD.gn | 37 ---- .../service/test/BUILD.gn | 10 +- .../service/test/udmf_run_time_store_test.cpp | 58 +++--- .../service/test/udmf_service_impl_test.cpp | 168 ++++++++++++++++-- .../service/udmf/udmf_service_impl.cpp | 22 +-- .../service/udmf/udmf_service_impl.h | 2 +- 7 files changed, 211 insertions(+), 90 deletions(-) diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index 30c770e8b..48e20c417 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -131,7 +131,7 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::GetHeadDataSize(uint32_t &headSize return DistributedDB::OK; } if (udmfStore && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { - ZLOGI("ignore older version device for udmf"); + ZLOGI("ignore older version device for udmf or object"); return DistributedDB::OK; } if (!session_.IsValid()) { @@ -294,7 +294,7 @@ bool RouteHeadHandlerImpl::ParseHeadDataLen(const uint8_t *data, uint32_t totalL return false; } if (udmfStore && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { - ZLOGI("ignore older version device for udmf"); + ZLOGI("ignore older version device for udmf or object"); return false; } diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 20c89c315..0af0be355 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -368,42 +368,6 @@ ohos_unittest("UpgradeManagerTest") { part_name = "datamgr_service" } -ohos_unittest("RouteHeadHandlerImplTest") { - module_out_path = module_output_path - - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - ] - - include_dirs = [ - "${data_service_path}/app/src/session_manager", - "${data_service_path}/app/test/mock/capability", - "${data_service_path}/framework/include", - "${data_service_path}/adapter/include", - ] - - sources = [ - "${data_service_path}/app/test/mock/capability/metadata/meta_data_manager.cpp", - "${data_service_path}/app/test/mock/capability/device_manager_adapter.cpp", - "${data_service_path}/app/src/session_manager/upgrade_manager.cpp", - "${data_service_path}/framework/metadata/capability_meta_data.cpp", - "${data_service_path}/framework/serializable/serializable.cpp", - "${data_service_path}/framework/utils/anonymous.cpp", - "${data_service_path}/framework/utils/constant.cpp", - "${data_service_path}/app/test/unittest/upgrade_manager_test.cpp", - ] - - external_deps = [ - "c_utils:utils", - "googletest:gtest_main", - "hilog:libhilog", - "cJSON:cjson", - "kv_store:distributeddata_inner", - ] - - part_name = "datamgr_service" -} ############################################################################### @@ -417,6 +381,5 @@ group("unittest") { ":KvStoreDataServiceTest", ":SessionManagerTest", ":UpgradeManagerTest", - ":RouteHeadHandlerImplTest", ] } \ No newline at end of file diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 4dbdfa8fe..fdf8c35dd 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1142,15 +1142,18 @@ ohos_unittest("UdmfServiceImplTest") { module_out_path = module_output_path sources = [ "${data_service_path}/framework/feature/feature_system.cpp", + "${data_service_path}/app/src/kvstore_meta_manager.cpp", "udmf_service_impl_test.cpp", ] include_dirs = [ + "${data_service_path}/adapter/include/account", + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/framework/include", "${data_service_path}/service/matrix/include", "${data_service_path}/service/udmf/preprocess", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", - "${data_service_path}/framework/include", "${data_service_path}/service/udmf/permission", "${data_service_path}/service/test/mock", ] @@ -1169,15 +1172,19 @@ ohos_unittest("UdmfServiceImplTest") { external_deps = [ "ability_runtime:uri_permission_mgr", "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "app_file_service:remote_file_share_native", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "dataclassification:data_transit_mgr", "device_manager:devicemanagersdk", "googletest:gmock_main", "googletest:gtest_main", "googletest:gtest_main", "hilog:libhilog", + "hisysevent:libhisysevent", "cJSON:cjson", "kv_store:distributeddata_inner", "kv_store:distributeddb", @@ -1206,6 +1213,7 @@ ohos_unittest("UdmfServiceStubTest") { ] deps = [ + "${data_service_path}/framework:distributeddatasvcfwk", "${data_service_path}/service:distributeddatasvc", "${data_service_path}/service/udmf:udmf_server", ] diff --git a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp index 962adbcbf..681c6dc03 100644 --- a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp +++ b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp @@ -118,7 +118,7 @@ void UdmfRunTimeStoreTest::GetRandomValue(std::vector& value, uint32_t * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries001, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries001, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -151,7 +151,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries002, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries002, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -184,7 +184,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries002, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries003, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries003, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -218,7 +218,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries003, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries004, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries004, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -259,7 +259,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries004, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries005, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries005, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -305,7 +305,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries005, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries001, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries001, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -346,7 +346,7 @@ HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries002, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries002, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -389,7 +389,7 @@ HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries002, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Init, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Init, TestSize.Level0) { auto dvInfo = DeviceManagerAdapter::GetInstance().GetLocalDevice(); auto uuid = DeviceManagerAdapter::GetInstance().GetUuidByNetworkId(EMPTY_DEVICE_ID); @@ -406,7 +406,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Init, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Get001, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Get001, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -441,7 +441,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Get001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Get002, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Get002, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -474,7 +474,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Get002, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -513,7 +513,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData01, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData01, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -557,7 +557,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData01, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync01, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Sync01, TestSize.Level0) { std::vector devices = {"device"}; auto store = std::make_shared(STORE_ID); @@ -573,7 +573,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync01, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync02, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Sync02, TestSize.Level0) { std::vector devices = { }; auto store = std::make_shared(STORE_ID); @@ -589,7 +589,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync02, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync03, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Sync03, TestSize.Level0) { std::vector devices = { "device" }; ProcessCallback callback; @@ -606,7 +606,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync03, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync04, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Sync04, TestSize.Level0) { std::vector devices = { }; ProcessCallback callback; @@ -623,7 +623,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync04, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Clear01, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Clear01, TestSize.Level0) { static constexpr const char *DATA_PREFIX = "udmf://"; auto store = std::make_shared(STORE_ID); @@ -639,7 +639,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Clear01, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Close01, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, Close01, TestSize.Level0) { auto store = std::make_shared(STORE_ID); EXPECT_NO_FATAL_FAILURE(store->Close()); @@ -652,7 +652,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Close01, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetSummary, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, GetSummary, TestSize.Level0) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -677,7 +677,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetSummary, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetRuntime001, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, GetRuntime001, TestSize.Level0) { UnifiedData inputData; CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; @@ -703,7 +703,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetRuntime001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level1) +HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level0) { UnifiedData inputData; CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; @@ -719,5 +719,21 @@ HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level1) status = store->GetRuntime(key, outRuntime); EXPECT_EQ(status, E_NOT_FOUND); } + +/** +* @tc.name: SaveMetaData001 +* @tc.desc: Abnormal testcase of GetRuntime +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(UdmfRunTimeStoreTest, SaveMetaData001, TestSize.Level0) +{ + auto store = std::make_shared(STORE_ID); + bool result = store->Init(); + EXPECT_TRUE(result); + + result = store->Init(); + EXPECT_TRUE(result); +} }; // namespace DistributedDataTest }; // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp index a553a863e..4cf7b910e 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp @@ -13,17 +13,52 @@ * limitations under the License. */ +#include "metadata/meta_data_manager.h" #define LOG_TAG "UdmfServiceImplTest" #include "udmf_service_impl.h" #include "gtest/gtest.h" #include "error_code.h" #include "text.h" +#include "accesstoken_kit.h" +#include "bootstrap.h" +#include "device_manager_adapter.h" +#include "executor_pool.h" +#include "ipc_skeleton.h" #include "mock/access_token_mock.h" #include "mock/meta_data_manager_mock.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" +#include "kvstore_meta_manager.h" using namespace OHOS::DistributedData; using namespace OHOS::Security::AccessToken; -namespace OHOS::UDMF { +using namespace OHOS::UDMF; +using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using namespace testing::ext; + +namespace OHOS::Test { +namespace DistributedDataTest { +static void GrantPermissionNative() +{ + const char **perms = new const char *[3]; + perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; + perms[1] = "ohos.permission.ACCESS_SERVICE_DM"; + perms[2] = "ohos.permission.MONITOR_DEVICE_NETWORK_STATE"; // perms[2] is a permission parameter + TokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 3, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "distributed_data_test", + .aplStr = "system_basic", + }; + uint64_t tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + AccessTokenKit::ReloadNativeTokenInfo(); + delete[] perms; +} + class UdmfServiceImplTest : public testing::Test { public: static void SetUpTestCase(void); @@ -36,6 +71,18 @@ public: }; void UdmfServiceImplTest::SetUpTestCase() { + GrantPermissionNative(); + DistributedData::Bootstrap::GetInstance().LoadComponents(); + DistributedData::Bootstrap::GetInstance().LoadDirectory(); + DistributedData::Bootstrap::GetInstance().LoadCheckers(); + size_t max = 2; + size_t min = 1; + auto executors = std::make_shared(max, min); + DmAdapter::GetInstance().Init(executors); + DistributedKv::KvStoreMetaManager::GetInstance().BindExecutor(executors); + DistributedKv::KvStoreMetaManager::GetInstance().InitMetaParameter(); + DistributedKv::KvStoreMetaManager::GetInstance().InitMetaListener(); + accTokenMock = std::make_shared(); BAccessTokenKit::accessTokenkit = accTokenMock; metaDataManagerMock = std::make_shared(); @@ -59,7 +106,7 @@ void UdmfServiceImplTest::TearDownTestCase(void) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SaveData001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, SaveData001, TestSize.Level0) { CustomOption option; UnifiedData data; @@ -76,7 +123,7 @@ HWTEST_F(UdmfServiceImplTest, SaveData001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, RetrieveData001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, RetrieveData001, TestSize.Level0) { QueryOption query; UnifiedData data; @@ -92,7 +139,7 @@ HWTEST_F(UdmfServiceImplTest, RetrieveData001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, IsPermissionInCache002, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, IsPermissionInCache002, TestSize.Level0) { QueryOption query; UdmfServiceImpl udmfServiceImpl; @@ -106,7 +153,7 @@ HWTEST_F(UdmfServiceImplTest, IsPermissionInCache002, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, UpdateData001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, UpdateData001, TestSize.Level0) { QueryOption query; UnifiedData data; @@ -121,7 +168,7 @@ HWTEST_F(UdmfServiceImplTest, UpdateData001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, GetSummary001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, GetSummary001, TestSize.Level0) { QueryOption query; Summary summary; @@ -136,7 +183,7 @@ HWTEST_F(UdmfServiceImplTest, GetSummary001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, Sync001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, Sync001, TestSize.Level0) { QueryOption query; std::vector devices = {"device1"}; @@ -151,7 +198,7 @@ HWTEST_F(UdmfServiceImplTest, Sync001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, IsRemoteData001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, IsRemoteData001, TestSize.Level0) { QueryOption query; bool result = false; @@ -166,7 +213,7 @@ HWTEST_F(UdmfServiceImplTest, IsRemoteData001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption001, TestSize.Level0) { std::string intention = ""; int32_t shareOption = 1; @@ -182,7 +229,7 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption002, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption002, TestSize.Level0) { std::string intention = "intention"; int32_t shareOption = 4; @@ -197,7 +244,7 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption002, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption003, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption003, TestSize.Level0) { std::string intention = "intention"; int32_t shareOption = 3; @@ -212,7 +259,7 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption003, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption004, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption004, TestSize.Level0) { std::string intention = "intention"; int32_t shareOption = -1; @@ -227,14 +274,14 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption004, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level0) { uint32_t code = 4; std::string user = "OH_USER_test"; std::string account = "OH_ACCOUNT_test"; UdmfServiceImpl udmfServiceImpl; auto status = udmfServiceImpl.OnUserChange(code, user, account); - ASSERT_EQ(status, E_OK); + ASSERT_EQ(status, UDMF::E_OK); auto sizeAfter = StoreCache::GetInstance().stores_.Size(); ASSERT_EQ(sizeAfter, 0); } @@ -245,7 +292,7 @@ HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level1) +HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level0) { UnifiedData data; QueryOption query; @@ -275,10 +322,97 @@ HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest001, TestSize.Level0) StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); std::vector devices = {"remote_device"}; + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(false)) + .WillOnce(testing::Return(false)); + auto isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, true); + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(false)) + .WillOnce(testing::Return(true)); + isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, false); + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) .WillOnce(testing::Return(true)) - .WillRepeatedly(testing::Return(true)); + .WillOnce(testing::Return(false)); + isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, false); + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(true)) + .WillOnce(testing::Return(true)); + isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, false); +} + +/** +* @tc.name: SyncTest001 +* @tc.desc: IsNeedMetaSync test matrix mask +* @tc.type: FUNC +*/ +HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest002, TestSize.Level0) +{ + QueryOption query; + query.key = "test_key"; + query.tokenId = 1; + query.intention = UD_INTENTION_DRAG; + UdmfServiceImpl udmfServiceImpl; + StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); + std::vector devices = {"remote_device"}; + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(false)) + .WillOnce(testing::Return(false)); auto isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); EXPECT_EQ(isNeedSync, true); + + // mock mask +} + +/** +* @tc.name: SyncTest001 +* @tc.desc: sync test +* @tc.type: FUNC +*/ +HWTEST_F(UdmfServiceImplTest, SyncTest001, TestSize.Level0) +{ + QueryOption query; + query.key = "test_key"; + query.tokenId = 1; + query.intention = UD_INTENTION_DRAG; + UdmfServiceImpl udmfServiceImpl; + StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); + std::vector devices = {"remote_device"}; + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(false)) + .WillOnce(testing::Return(false)); + auto ret = udmfServiceImpl.Sync(query, devices); + EXPECT_EQ(ret, UDMF::E_OK); +} + +/** + * @tc.name: ResolveAutoLaunch001 + * @tc.desc: ResolveAutoLaunch test. + * @tc.type: FUNC + */ +HWTEST_F(UdmfServiceImplTest, ResolveAutoLaunch001, TestSize.Level0) +{ + auto store = StoreCache::GetInstance().GetStore("drag"); + auto ret = store->Init(); + EXPECT_EQ(ret, UDMF::E_OK); + + DistributedDB::AutoLaunchParam param { + .userId = "100", + .appId = "distributeddata", + .storeId = "drag", + }; + std::string identifier = "identifier"; + std::shared_ptr udmfServiceImpl = std::make_shared(); + ret = udmfServiceImpl->ResolveAutoLaunch(identifier, param); + EXPECT_EQ(ret, UDMF::E_OK); } -}; // namespace UDMF \ No newline at end of file +} // DistributedDataTest +}; \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index ea248eb58..cb8e4e8e5 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -573,7 +573,6 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vectorGetUserByToken(IPCSkeleton::GetCallingFullTokenID()); StoreMetaData meta = StoreMetaData(std::to_string(userId), Bootstrap::GetInstance().GetProcessLabel(), key.intention); - if (IsNeedMetaSync(meta, devices) && !MetaDataManager::GetInstance().Sync(devices, [](auto &results) {})) { + auto uuids = DmAdapter::GetInstance().ToUUID(devices); + if (IsNeedMetaSync(meta, uuids) && !MetaDataManager::GetInstance().Sync(uuids, [this, devices, callback, store] + (auto &results) { + if (store->Sync(devices, callback) != E_OK) { + ZLOGE("Store sync failed"); + RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), + BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); + } + })) { ZLOGW("bundleName:%{public}s, meta sync failed", key.bundleName.c_str()); } - if (store->Sync(devices, callback) != E_OK) { - ZLOGE("Store sync failed:%{public}s", key.intention.c_str()); - RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), - BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); - return E_DB_ERROR; - } return E_OK; } @@ -1144,13 +1145,12 @@ int32_t UdmfServiceImpl::GetDataIfAvailable(const std::string &key, const DataLo return E_OK; } -bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vector &devices) +bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vector &uuids) { using namespace OHOS::DistributedData; bool isAfterMeta = false; - for (const auto &device : devices) { + for (const auto &uuid : uuids) { auto metaData = meta; - auto uuid = DeviceManagerAdapter::GetInstance().ToUUID(device); metaData.deviceId = uuid; CapMetaData capMeta; auto capKey = CapMetaRow::GetKeyFor(uuid); diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.h b/services/distributeddataservice/service/udmf/udmf_service_impl.h index 092f1ba57..e70b7e0c6 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.h +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.h @@ -77,7 +77,7 @@ private: bool IsFileMangerIntention(const std::string &intention); std::string FindIntentionMap(const Intention &queryintention); bool IsValidOptionsNonDrag(UnifiedKey &key, const std::string &intention); - bool IsNeedMetaSync(const DistributedData::StoreMetaData &meta, const std::vector &devices); + bool IsNeedMetaSync(const DistributedData::StoreMetaData &meta, const std::vector &uuids); class Factory { public: -- Gitee From b5424c1515f4ce7d5068226a3819a61225bacde5 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sun, 8 Jun 2025 17:23:11 +0800 Subject: [PATCH 12/22] add test case Signed-off-by: wanghuajian-6 --- .../route_head_handler_impl.cpp | 18 +- .../session_manager/route_head_handler_impl.h | 1 - .../framework/directory/directory_manager.cpp | 4 +- .../service/test/BUILD.gn | 60 ++++- .../service/test/directory_manager_test.cpp | 30 +++ .../service/test/udmf_run_time_store_test.cpp | 58 ++--- .../test/udmf_service_impl_mock_test.cpp | 176 +++++++++++++ .../service/test/udmf_service_impl_test.cpp | 232 ++++++------------ .../service/udmf/udmf_service_impl.cpp | 13 +- 9 files changed, 380 insertions(+), 212 deletions(-) create mode 100644 services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp index 48e20c417..01c16a239 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.cpp @@ -39,7 +39,6 @@ using DmAdapter = DistributedData::DeviceManagerAdapter; using DBManager = DistributedDB::KvStoreDelegateManager; constexpr const int ALIGN_WIDTH = 8; constexpr const char *DEFAULT_USERID = "0"; -constexpr const char *UDMF_DRAG_STORE = "drag"; std::shared_ptr RouteHeadHandlerImpl::Create(const ExtendInfo &info) { auto handler = std::make_shared(info); @@ -74,7 +73,7 @@ void RouteHeadHandlerImpl::Init() userId_ = DEFAULT_USERID; } } - if (IsUdmfStore()) { + if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ != Bootstrap::GetInstance().GetMetaDBName()) { int foregroundUserId = 0; AccountDelegate::GetInstance()->QueryForegroundUserId(foregroundUserId); userId_ = std::to_string(foregroundUserId); @@ -102,8 +101,7 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::GetHeadDataSize(uint32_t &headSize { ZLOGD("begin"); headSize = 0; - bool udmfStore = IsUdmfStore(); - if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && !udmfStore) { + if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ == Bootstrap::GetInstance().GetMetaDBName()) { ZLOGI("meta data permitted"); return DistributedDB::OK; } @@ -130,7 +128,8 @@ DistributedDB::DBStatus RouteHeadHandlerImpl::GetHeadDataSize(uint32_t &headSize ZLOGI("ignore older version device"); return DistributedDB::OK; } - if (udmfStore && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { + if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ != Bootstrap::GetInstance().GetMetaDBName() + && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { ZLOGI("ignore older version device for udmf or object"); return DistributedDB::OK; } @@ -287,13 +286,13 @@ bool RouteHeadHandlerImpl::ParseHeadDataLen(const uint8_t *data, uint32_t totalL } bool flag = false; - bool udmfStore = IsUdmfStore(); auto peerCap = UpgradeManager::GetInstance().GetCapability(device, flag); if (!flag) { ZLOGI("get peer cap failed"); return false; } - if (udmfStore && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { + if (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ != Bootstrap::GetInstance().GetMetaDBName() + && peerCap.version < CapMetaData::UDMF_AND_OBJECT_VERSION) { ZLOGI("ignore older version device for udmf or object"); return false; } @@ -521,9 +520,4 @@ bool RouteHeadHandlerImpl::UnPackAccountId(uint8_t **data, uint32_t leftSize) session_.accountId = std::string(accountId->accountId, accountIdLen); return true; } - -bool RouteHeadHandlerImpl::IsUdmfStore() -{ - return (appId_ == Bootstrap::GetInstance().GetProcessLabel() && storeId_ == UDMF_DRAG_STORE); -} } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h index 87b5e7fdd..85611780b 100644 --- a/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h +++ b/services/distributeddataservice/app/src/session_manager/route_head_handler_impl.h @@ -92,7 +92,6 @@ private: bool UnPackStoreId(uint8_t **data, uint32_t leftSize); bool UnPackAccountId(uint8_t **data, uint32_t leftSize); std::string ParseStoreId(const std::string &deviceId, const std::string &label); - bool IsUdmfStore(); std::string userId_; std::string appId_; std::string storeId_; diff --git a/services/distributeddataservice/framework/directory/directory_manager.cpp b/services/distributeddataservice/framework/directory/directory_manager.cpp index 4b1786a56..8ac7b2f03 100644 --- a/services/distributeddataservice/framework/directory/directory_manager.cpp +++ b/services/distributeddataservice/framework/directory/directory_manager.cpp @@ -181,9 +181,7 @@ std::string DirectoryManager::GetArea(const StoreMetaData &metaData) const std::string DirectoryManager::GetUserId(const StoreMetaData &metaData) const { auto type = AccessTokenKit::GetTokenTypeFlag(metaData.tokenId); - if ((type == TOKEN_NATIVE || type == TOKEN_SHELL) && (metaData.user == StoreMetaData::ROOT_USER) && - (metaData.storeType < StoreMetaData::StoreType::STORE_UDMF_BEGIN || - metaData.storeType >= StoreMetaData::StoreType::STORE_UDMF_END)) { + if ((type == TOKEN_NATIVE || type == TOKEN_SHELL) && (metaData.user == StoreMetaData::ROOT_USER)) { return "public"; } return metaData.user; diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index fdf8c35dd..613b32c08 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1146,6 +1146,64 @@ ohos_unittest("UdmfServiceImplTest") { "udmf_service_impl_test.cpp", ] + include_dirs = [ + "${data_service_path}/adapter/include/account", + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/app/src", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/permission", + ] + + configs = [ ":module_private_config" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "dataclassification:data_transit_mgr", + "device_manager:devicemanagersdk", + "dsoftbus:softbus_client", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "image_framework:image", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddb", + "openssl:libcrypto_shared", + "samgr:samgr_proxy", + "safwk:system_ability_fwk", + "udmf:udmf_client", + ] + + deps = [ + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service:distributeddatasvc", + "${data_service_path}/service/udmf:udmf_server", + ] + + defines = [ + "private=public", + "protected=public", + ] +} + +ohos_unittest("UdmfServiceImplMockTest") { + module_out_path = module_output_path + sources = [ + "${data_service_path}/framework/feature/feature_system.cpp", + "udmf_service_impl_mock_test.cpp", + ] + include_dirs = [ "${data_service_path}/adapter/include/account", "${data_service_path}/adapter/include/communicator", @@ -1182,7 +1240,6 @@ ohos_unittest("UdmfServiceImplTest") { "device_manager:devicemanagersdk", "googletest:gmock_main", "googletest:gtest_main", - "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", "cJSON:cjson", @@ -1890,6 +1947,7 @@ group("unittest") { ":UdmfPreProcessUtilsMockTest", ":UdmfPreProcessUtilsTest", ":UdmfRunTimeStoreTest", + ":UdmfServiceImplMockTest", ":UdmfServiceImplTest", ":UdmfServiceStubMockTest", ":UdmfServiceStubTest", diff --git a/services/distributeddataservice/service/test/directory_manager_test.cpp b/services/distributeddataservice/service/test/directory_manager_test.cpp index c763765ab..f2765fe03 100644 --- a/services/distributeddataservice/service/test/directory_manager_test.cpp +++ b/services/distributeddataservice/service/test/directory_manager_test.cpp @@ -191,6 +191,36 @@ HWTEST_F(DirectoryManagerTest, GetKVDBBackupPath, TestSize.Level0) EXPECT_EQ(path, metaData.dataDir + "/backup/testStpre"); } +/** +* @tc.name: GetUdmfPath +* @tc.desc: test get udmf store path +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(DirectoryManagerTest, GetUdmfStorePath, TestSize.Level0) +{ + StoreMetaData metaData; + metaData.user = "100"; + metaData.bundleName = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); + metaData.appId = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); + metaData.storeId = "drag"; + metaData.securityLevel = SecurityLevel::S2; + metaData.area = 1; + metaData.storeType = 0; + metaData.tokenId = GetAccessTokenId(&tokenParam_); + metaData.appId = "ohos.test.demo_09AEF01D"; + metaData.area = DistributedKv::Area::EL2; + metaData.uid = static_cast(getuid()); + metaData.storeType = StoreMetaData::StoreType::STORE_UDMF_BEGIN; + metaData.dataType = DistributedKv::DataType::TYPE_DYNAMICAL; + metaData.authType = DistributedKv::AuthType::IDENTICAL_ACCOUNT; + metaData.dataDir = "/data/service/el2/100/database/distributeddata/other"; + auto path = DirectoryManager::GetInstance().GetStorePath(metaData); + EXPECT_EQ(path, metaData.dataDir); + auto res = DistributedData::DirectoryManager::GetInstance().CreateDirectory(path); + EXPECT_EQ(res, true); +} + /** * @tc.name: GetStorageMetaPath * @tc.desc: test get meta store dir diff --git a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp index 681c6dc03..962adbcbf 100644 --- a/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp +++ b/services/distributeddataservice/service/test/udmf_run_time_store_test.cpp @@ -118,7 +118,7 @@ void UdmfRunTimeStoreTest::GetRandomValue(std::vector& value, uint32_t * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries001, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries001, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -151,7 +151,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries002, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries002, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -184,7 +184,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries002, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries003, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries003, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -218,7 +218,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries003, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries004, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries004, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -259,7 +259,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries004, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, PutEntries005, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, PutEntries005, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -305,7 +305,7 @@ HWTEST_F(UdmfRunTimeStoreTest, PutEntries005, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries001, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries001, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -346,7 +346,7 @@ HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries002, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries002, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -389,7 +389,7 @@ HWTEST_F(UdmfRunTimeStoreTest, DeleteEntries002, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Init, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Init, TestSize.Level1) { auto dvInfo = DeviceManagerAdapter::GetInstance().GetLocalDevice(); auto uuid = DeviceManagerAdapter::GetInstance().GetUuidByNetworkId(EMPTY_DEVICE_ID); @@ -406,7 +406,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Init, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Get001, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Get001, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -441,7 +441,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Get001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Get002, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Get002, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -474,7 +474,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Get002, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -513,7 +513,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData01, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData01, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -557,7 +557,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetDetailsFromUData01, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync01, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Sync01, TestSize.Level1) { std::vector devices = {"device"}; auto store = std::make_shared(STORE_ID); @@ -573,7 +573,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync01, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync02, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Sync02, TestSize.Level1) { std::vector devices = { }; auto store = std::make_shared(STORE_ID); @@ -589,7 +589,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync02, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync03, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Sync03, TestSize.Level1) { std::vector devices = { "device" }; ProcessCallback callback; @@ -606,7 +606,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync03, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Sync04, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Sync04, TestSize.Level1) { std::vector devices = { }; ProcessCallback callback; @@ -623,7 +623,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Sync04, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Clear01, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Clear01, TestSize.Level1) { static constexpr const char *DATA_PREFIX = "udmf://"; auto store = std::make_shared(STORE_ID); @@ -639,7 +639,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Clear01, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, Close01, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, Close01, TestSize.Level1) { auto store = std::make_shared(STORE_ID); EXPECT_NO_FATAL_FAILURE(store->Close()); @@ -652,7 +652,7 @@ HWTEST_F(UdmfRunTimeStoreTest, Close01, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetSummary, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, GetSummary, TestSize.Level1) { auto store = std::make_shared(STORE_ID); bool result = store->Init(); @@ -677,7 +677,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetSummary, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetRuntime001, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, GetRuntime001, TestSize.Level1) { UnifiedData inputData; CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; @@ -703,7 +703,7 @@ HWTEST_F(UdmfRunTimeStoreTest, GetRuntime001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level0) +HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level1) { UnifiedData inputData; CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; @@ -719,21 +719,5 @@ HWTEST_F(UdmfRunTimeStoreTest, GetRuntime002, TestSize.Level0) status = store->GetRuntime(key, outRuntime); EXPECT_EQ(status, E_NOT_FOUND); } - -/** -* @tc.name: SaveMetaData001 -* @tc.desc: Abnormal testcase of GetRuntime -* @tc.type: FUNC -* @tc.require: -*/ -HWTEST_F(UdmfRunTimeStoreTest, SaveMetaData001, TestSize.Level0) -{ - auto store = std::make_shared(STORE_ID); - bool result = store->Init(); - EXPECT_TRUE(result); - - result = store->Init(); - EXPECT_TRUE(result); -} }; // namespace DistributedDataTest }; // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp new file mode 100644 index 000000000..9143f0ba6 --- /dev/null +++ b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp @@ -0,0 +1,176 @@ +/* +* 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. +*/ + +#include "metadata/meta_data_manager.h" +#define LOG_TAG "UdmfServiceImplTest" +#include "udmf_service_impl.h" +#include "gtest/gtest.h" +#include "error_code.h" +#include "text.h" +#include "accesstoken_kit.h" +#include "bootstrap.h" +#include "device_manager_adapter.h" +#include "executor_pool.h" +#include "ipc_skeleton.h" +#include "mock/access_token_mock.h" +#include "mock/meta_data_manager_mock.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" +#include "kvstore_meta_manager.h" +using namespace OHOS::DistributedData; +using namespace OHOS::Security::AccessToken; +using namespace OHOS::UDMF; +using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +using namespace testing::ext; + +namespace OHOS::Test { +namespace DistributedDataTest { +class UdmfServiceImplTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + static inline std::shared_ptr accTokenMock = nullptr; + static inline std::shared_ptr metaDataManagerMock = nullptr; + static inline std::shared_ptr> metaDataMock = nullptr; + void SetUp() {} + void TearDown() {} +}; +void UdmfServiceImplTest::SetUpTestCase() +{ + accTokenMock = std::make_shared(); + BAccessTokenKit::accessTokenkit = accTokenMock; + metaDataManagerMock = std::make_shared(); + BMetaDataManager::metaDataManager = metaDataManagerMock; + metaDataMock = std::make_shared>(); + BMetaData::metaDataManager = metaDataMock; +} + +void UdmfServiceImplTest::TearDownTestCase(void) +{ + accTokenMock = nullptr; + BAccessTokenKit::accessTokenkit = nullptr; + metaDataManagerMock = nullptr; + BMetaDataManager::metaDataManager = nullptr; + metaDataMock = nullptr; + BMetaData::metaDataManager = nullptr; +} + +/** +* @tc.name: TransferToEntriesIfNeedTest001 +* @tc.desc: TransferToEntriesIfNeed test +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level0) +{ + UnifiedData data; + QueryOption query; + auto record1 = std::make_shared(); + auto record2 = std::make_shared(); + data.AddRecord(record1); + data.AddRecord(record2); + auto properties = std::make_shared(); + properties->tag = "records_to_entries_data_format"; + data.SetProperties(properties); + query.tokenId = 1; + UdmfServiceImpl udmfServiceImpl; + udmfServiceImpl.TransferToEntriesIfNeed(query, data); + EXPECT_TRUE(data.IsNeedTransferToEntries()); + int recordSize = 2; + EXPECT_EQ(data.GetRecords().size(), recordSize); +} + +/** +* @tc.name: IsNeedMetaSyncTest001 +* @tc.desc: IsNeedMetaSync test +* @tc.type: FUNC +*/ +HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest001, TestSize.Level0) +{ + UdmfServiceImpl udmfServiceImpl; + StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); + std::vector devices = {"remote_device"}; + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(false)) + .WillOnce(testing::Return(false)); + auto isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, true); + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(false)) + .WillOnce(testing::Return(true)); + isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, true); + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(true)) + .WillOnce(testing::Return(false)); + isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, true); + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(true)) + .WillOnce(testing::Return(true)); + isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, false); +} + +/** +* @tc.name: SyncTest001 +* @tc.desc: IsNeedMetaSync test matrix mask +* @tc.type: FUNC +*/ +HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest002, TestSize.Level0) +{ + QueryOption query; + query.key = "test_key"; + query.tokenId = 1; + query.intention = UD_INTENTION_DRAG; + UdmfServiceImpl udmfServiceImpl; + StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); + std::vector devices = {"remote_device"}; + + EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(false)) + .WillOnce(testing::Return(false)); + auto isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); + EXPECT_EQ(isNeedSync, true); + // mock mask +} + +/** + * @tc.name: ResolveAutoLaunchTest001 + * @tc.desc: ResolveAutoLaunch test. + * @tc.type: FUNC + */ +HWTEST_F(UdmfServiceImplTest, ResolveAutoLaunchTest001, TestSize.Level0) +{ + auto store = StoreCache::GetInstance().GetStore("drag"); + auto ret = store->Init(); + EXPECT_EQ(ret, UDMF::E_OK); + + DistributedDB::AutoLaunchParam param { + .userId = "100", + .appId = "distributeddata", + .storeId = "drag", + }; + std::string identifier = "identifier"; + std::shared_ptr udmfServiceImpl = std::make_shared(); + ret = udmfServiceImpl->ResolveAutoLaunch(identifier, param); + EXPECT_EQ(ret, UDMF::E_NOT_FOUND); +} +} // DistributedDataTest +}; \ No newline at end of file diff --git a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp index 4cf7b910e..1910cc7cd 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp @@ -13,30 +13,37 @@ * limitations under the License. */ -#include "metadata/meta_data_manager.h" +#include "error_code.h" #define LOG_TAG "UdmfServiceImplTest" +#include #include "udmf_service_impl.h" -#include "gtest/gtest.h" -#include "error_code.h" -#include "text.h" #include "accesstoken_kit.h" #include "bootstrap.h" #include "device_manager_adapter.h" #include "executor_pool.h" +#include "gtest/gtest.h" #include "ipc_skeleton.h" -#include "mock/access_token_mock.h" -#include "mock/meta_data_manager_mock.h" +#include "kvstore_meta_manager.h" +#include "metadata/meta_data_manager.h" #include "nativetoken_kit.h" +#include "preprocess_utils.h" +#include "runtime_store.h" +#include "text.h" #include "token_setproc.h" -#include "kvstore_meta_manager.h" + +using namespace testing::ext; using namespace OHOS::DistributedData; using namespace OHOS::Security::AccessToken; using namespace OHOS::UDMF; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; -using namespace testing::ext; - +using Entry = DistributedDB::Entry; +using Key = DistributedDB::Key; +using Value = DistributedDB::Value; +using UnifiedData = OHOS::UDMF::UnifiedData; +using Summary = OHOS::UDMF::Summary; namespace OHOS::Test { namespace DistributedDataTest { + static void GrantPermissionNative() { const char **perms = new const char *[3]; @@ -61,52 +68,39 @@ static void GrantPermissionNative() class UdmfServiceImplTest : public testing::Test { public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - static inline std::shared_ptr accTokenMock = nullptr; - static inline std::shared_ptr metaDataManagerMock = nullptr; - static inline std::shared_ptr> metaDataMock = nullptr; - void SetUp() {} - void TearDown() {} -}; -void UdmfServiceImplTest::SetUpTestCase() -{ - GrantPermissionNative(); - DistributedData::Bootstrap::GetInstance().LoadComponents(); - DistributedData::Bootstrap::GetInstance().LoadDirectory(); - DistributedData::Bootstrap::GetInstance().LoadCheckers(); - size_t max = 2; - size_t min = 1; - auto executors = std::make_shared(max, min); - DmAdapter::GetInstance().Init(executors); - DistributedKv::KvStoreMetaManager::GetInstance().BindExecutor(executors); - DistributedKv::KvStoreMetaManager::GetInstance().InitMetaParameter(); - DistributedKv::KvStoreMetaManager::GetInstance().InitMetaListener(); + static void SetUpTestCase(void) + { + GrantPermissionNative(); + DistributedData::Bootstrap::GetInstance().LoadComponents(); + DistributedData::Bootstrap::GetInstance().LoadDirectory(); + DistributedData::Bootstrap::GetInstance().LoadCheckers(); + size_t max = 2; + size_t min = 1; + auto executors = std::make_shared(max, min); + DmAdapter::GetInstance().Init(executors); + DistributedKv::KvStoreMetaManager::GetInstance().BindExecutor(executors); + DistributedKv::KvStoreMetaManager::GetInstance().InitMetaParameter(); + DistributedKv::KvStoreMetaManager::GetInstance().InitMetaListener(); + } + static void TearDownTestCase(void){}; + void SetUp(){}; + void TearDown(){}; - accTokenMock = std::make_shared(); - BAccessTokenKit::accessTokenkit = accTokenMock; - metaDataManagerMock = std::make_shared(); - BMetaDataManager::metaDataManager = metaDataManagerMock; - metaDataMock = std::make_shared>(); - BMetaData::metaDataManager = metaDataMock; -} + const uint32_t MAX_KEY_SIZE = 1024; + const uint32_t MAX_VALUE_SIZE = 4 * 1024 * 1024; + const std::string STORE_ID = "drag"; + const std::string KEY_PREFIX = "TEST_"; + const std::string EMPTY_DEVICE_ID = ""; + static constexpr size_t tempUdataRecordSize = 1; +}; -void UdmfServiceImplTest::TearDownTestCase(void) -{ - accTokenMock = nullptr; - BAccessTokenKit::accessTokenkit = nullptr; - metaDataManagerMock = nullptr; - BMetaDataManager::metaDataManager = nullptr; - metaDataMock = nullptr; - BMetaData::metaDataManager = nullptr; -} /** * @tc.name: SaveData001 * @tc.desc: Abnormal test of SaveData, unifiedData is invalid * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SaveData001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, SaveData001, TestSize.Level1) { CustomOption option; UnifiedData data; @@ -123,7 +117,7 @@ HWTEST_F(UdmfServiceImplTest, SaveData001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, RetrieveData001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, RetrieveData001, TestSize.Level1) { QueryOption query; UnifiedData data; @@ -139,7 +133,7 @@ HWTEST_F(UdmfServiceImplTest, RetrieveData001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, IsPermissionInCache002, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, IsPermissionInCache002, TestSize.Level1) { QueryOption query; UdmfServiceImpl udmfServiceImpl; @@ -153,7 +147,7 @@ HWTEST_F(UdmfServiceImplTest, IsPermissionInCache002, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, UpdateData001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, UpdateData001, TestSize.Level1) { QueryOption query; UnifiedData data; @@ -168,7 +162,7 @@ HWTEST_F(UdmfServiceImplTest, UpdateData001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, GetSummary001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, GetSummary001, TestSize.Level1) { QueryOption query; Summary summary; @@ -183,7 +177,7 @@ HWTEST_F(UdmfServiceImplTest, GetSummary001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, Sync001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, Sync001, TestSize.Level1) { QueryOption query; std::vector devices = {"device1"}; @@ -198,7 +192,7 @@ HWTEST_F(UdmfServiceImplTest, Sync001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, IsRemoteData001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, IsRemoteData001, TestSize.Level1) { QueryOption query; bool result = false; @@ -213,7 +207,7 @@ HWTEST_F(UdmfServiceImplTest, IsRemoteData001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption001, TestSize.Level1) { std::string intention = ""; int32_t shareOption = 1; @@ -229,7 +223,7 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption001, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption002, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption002, TestSize.Level1) { std::string intention = "intention"; int32_t shareOption = 4; @@ -244,7 +238,7 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption002, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption003, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption003, TestSize.Level1) { std::string intention = "intention"; int32_t shareOption = 3; @@ -259,7 +253,7 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption003, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, SetAppShareOption004, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, SetAppShareOption004, TestSize.Level1) { std::string intention = "intention"; int32_t shareOption = -1; @@ -274,7 +268,7 @@ HWTEST_F(UdmfServiceImplTest, SetAppShareOption004, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level1) { uint32_t code = 4; std::string user = "OH_USER_test"; @@ -287,123 +281,53 @@ HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level0) } /** -* @tc.name: TransferToEntriesIfNeedTest001 -* @tc.desc: TransferToEntriesIfNeed test +* @tc.name: SaveMetaData001 +* @tc.desc: Abnormal testcase of GetRuntime * @tc.type: FUNC * @tc.require: */ -HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level0) +HWTEST_F(UdmfServiceImplTest, SaveMetaData001, TestSize.Level0) { - UnifiedData data; - QueryOption query; - auto record1 = std::make_shared(); - auto record2 = std::make_shared(); - data.AddRecord(record1); - data.AddRecord(record2); - auto properties = std::make_shared(); - properties->tag = "records_to_entries_data_format"; - data.SetProperties(properties); - query.tokenId = 1; - UdmfServiceImpl udmfServiceImpl; - udmfServiceImpl.TransferToEntriesIfNeed(query, data); - EXPECT_TRUE(data.IsNeedTransferToEntries()); - int recordSize = 2; - EXPECT_EQ(data.GetRecords().size(), recordSize); + auto store = std::make_shared(STORE_ID); + bool result = store->Init(); + EXPECT_TRUE(result); + + result = store->Init(); + EXPECT_TRUE(result); } /** -* @tc.name: IsNeedMetaSyncTest001 -* @tc.desc: IsNeedMetaSync test -* @tc.type: FUNC -*/ -HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest001, TestSize.Level0) -{ - UdmfServiceImpl udmfServiceImpl; - StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); - std::vector devices = {"remote_device"}; - - EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) - .WillOnce(testing::Return(false)) - .WillOnce(testing::Return(false)); - auto isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); - EXPECT_EQ(isNeedSync, true); - - EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) - .WillOnce(testing::Return(false)) - .WillOnce(testing::Return(true)); - isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); - EXPECT_EQ(isNeedSync, false); - - EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) - .WillOnce(testing::Return(true)) - .WillOnce(testing::Return(false)); - isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); - EXPECT_EQ(isNeedSync, false); - - EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) - .WillOnce(testing::Return(true)) - .WillOnce(testing::Return(true)); - isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); - EXPECT_EQ(isNeedSync, false); -} - -/** -* @tc.name: SyncTest001 -* @tc.desc: IsNeedMetaSync test matrix mask -* @tc.type: FUNC -*/ -HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest002, TestSize.Level0) -{ - QueryOption query; - query.key = "test_key"; - query.tokenId = 1; - query.intention = UD_INTENTION_DRAG; - UdmfServiceImpl udmfServiceImpl; - StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); - std::vector devices = {"remote_device"}; - - EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) - .WillOnce(testing::Return(false)) - .WillOnce(testing::Return(false)); - auto isNeedSync = udmfServiceImpl.IsNeedMetaSync(meta, devices); - EXPECT_EQ(isNeedSync, true); - - // mock mask -} - -/** -* @tc.name: SyncTest001 -* @tc.desc: sync test +* @tc.name: SaveMetaData001 +* @tc.desc: Abnormal testcase of GetRuntime * @tc.type: FUNC +* @tc.require: */ HWTEST_F(UdmfServiceImplTest, SyncTest001, TestSize.Level0) { QueryOption query; - query.key = "test_key"; + query.key = "udmf://drag/ohos.test.demo1/_aS6adWi7 devices = {"remote_device"}; - EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) - .WillOnce(testing::Return(false)) - .WillOnce(testing::Return(false)); auto ret = udmfServiceImpl.Sync(query, devices); - EXPECT_EQ(ret, UDMF::E_OK); + EXPECT_EQ(ret, UDMF::E_DB_ERROR); } /** - * @tc.name: ResolveAutoLaunch001 - * @tc.desc: ResolveAutoLaunch test. - * @tc.type: FUNC - */ +* @tc.name: ResolveAutoLaunch001 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: +*/ HWTEST_F(UdmfServiceImplTest, ResolveAutoLaunch001, TestSize.Level0) { - auto store = StoreCache::GetInstance().GetStore("drag"); - auto ret = store->Init(); - EXPECT_EQ(ret, UDMF::E_OK); - + auto store = std::make_shared(STORE_ID); + bool result = store->Init(); + EXPECT_TRUE(result); + DistributedDB::AutoLaunchParam param { .userId = "100", .appId = "distributeddata", @@ -411,8 +335,8 @@ HWTEST_F(UdmfServiceImplTest, ResolveAutoLaunch001, TestSize.Level0) }; std::string identifier = "identifier"; std::shared_ptr udmfServiceImpl = std::make_shared(); - ret = udmfServiceImpl->ResolveAutoLaunch(identifier, param); + auto ret = udmfServiceImpl->ResolveAutoLaunch(identifier, param); EXPECT_EQ(ret, UDMF::E_OK); } -} // DistributedDataTest -}; \ No newline at end of file +}; // namespace DistributedDataTest +}; // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index cb8e4e8e5..f06d34e64 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -563,7 +563,6 @@ int32_t UdmfServiceImpl::AddPrivilege(const QueryOption &query, Privilege &privi int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vector &devices) { - ZLOGD("start"); RadarReporterAdapter::ReportNormal(std::string(__FUNCTION__), BizScene::SYNC_DATA, SyncDataStage::SYNC_BEGIN, StageRes::IDLE, BizState::DFX_BEGIN); UnifiedKey key(query.key); @@ -594,10 +593,10 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vectorGetUserByToken(IPCSkeleton::GetCallingFullTokenID()); - StoreMetaData meta = StoreMetaData(std::to_string(userId), Bootstrap::GetInstance().GetProcessLabel(), key.intention); + int32_t id = AccountDelegate::GetInstance()->GetUserByToken(IPCSkeleton::GetCallingFullTokenID()); + StoreMetaData meta = StoreMetaData(std::to_string(id), Bootstrap::GetInstance().GetProcessLabel(), key.intention); auto uuids = DmAdapter::GetInstance().ToUUID(devices); - if (IsNeedMetaSync(meta, uuids) && !MetaDataManager::GetInstance().Sync(uuids, [this, devices, callback, store] + if (IsNeedMetaSync(meta, uuids) && !MetaDataManager::GetInstance().Sync(uuids, [devices, callback, store] (auto &results) { if (store->Sync(devices, callback) != E_OK) { ZLOGE("Store sync failed"); @@ -607,6 +606,12 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vectorSync(devices, callback) != E_OK) { + ZLOGE("Store sync failed"); + RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), + BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); + return UDMF::E_DB_ERROR; + } return E_OK; } -- Gitee From ee45657f3a00f984215a0c64bf1a3f42bbc525b9 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sun, 8 Jun 2025 17:25:36 +0800 Subject: [PATCH 13/22] add test case Signed-off-by: wanghuajian-6 --- .../service/test/directory_manager_test.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/services/distributeddataservice/service/test/directory_manager_test.cpp b/services/distributeddataservice/service/test/directory_manager_test.cpp index f2765fe03..a71c6df46 100644 --- a/services/distributeddataservice/service/test/directory_manager_test.cpp +++ b/services/distributeddataservice/service/test/directory_manager_test.cpp @@ -205,10 +205,7 @@ HWTEST_F(DirectoryManagerTest, GetUdmfStorePath, TestSize.Level0) metaData.appId = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); metaData.storeId = "drag"; metaData.securityLevel = SecurityLevel::S2; - metaData.area = 1; - metaData.storeType = 0; metaData.tokenId = GetAccessTokenId(&tokenParam_); - metaData.appId = "ohos.test.demo_09AEF01D"; metaData.area = DistributedKv::Area::EL2; metaData.uid = static_cast(getuid()); metaData.storeType = StoreMetaData::StoreType::STORE_UDMF_BEGIN; -- Gitee From da042f580803ae4f0bf3a11218646e54307668ea Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sun, 8 Jun 2025 17:32:51 +0800 Subject: [PATCH 14/22] add test case Signed-off-by: wanghuajian-6 --- .../distributeddataservice/app/test/BUILD.gn | 1 - .../unittest/route_head_handler_impl_test.cpp | 94 ------------------- .../test/unittest/session_manager_test.cpp | 35 +++---- .../service/test/udmf_service_impl_test.cpp | 25 +++++ 4 files changed, 38 insertions(+), 117 deletions(-) delete mode 100644 services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 0af0be355..bfb70673a 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -368,7 +368,6 @@ ohos_unittest("UpgradeManagerTest") { part_name = "datamgr_service" } - ############################################################################### group("unittest") { diff --git a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp deleted file mode 100644 index baed04172..000000000 --- a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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. - */ - -#include "route_head_handler_impl.h" - -#include "upgrade_manager.h" - -#include - -#include "device_manager_adapter.h" -#include "metadata/meta_data_manager.h" -using namespace testing; -using namespace testing::ext; -using namespace OHOS; -using namespace OHOS::DistributedData; -using namespace OHOS::DistributedKv; -using namespace DistributedDB; - -static constexpr size_t THREAD_MIN = 0; -static constexpr size_t THREAD_MAX = 2; -static constexpr const char* REMOTE_DEVICE = "0123456789ABCDEF"; - -class RouteHeadHandlerImplTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void) {}; - void SetUp() {}; - void TearDown() {}; - - static std::shared_ptr executors_; - static std::string localDevice_; -}; -static inline std::shared_ptr deviceManagerAdapterMock = nullptr; -std::shared_ptr RouteHeadHandlerImplTest::executors_; -std::string RouteHeadHandlerImplTest::localDevice_; - -void RouteHeadHandlerImplTest::SetUpTestCase(void) -{ - localDevice_ = DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid; - executors_ = std::make_shared(THREAD_MAX, THREAD_MIN); - MetaDataManager::GetInstance().Init(executors_); - UpgradeManager::GetInstance().Init(executors_); - deviceManagerAdapterMock = std::make_shared(); - BDeviceManagerAdapter::deviceManagerAdapter = deviceManagerAdapterMock; - sleep(1); -} - -/** -* @tc.name: GetHeadDataSize_Test1 -* @tc.desc: get headSize for udmf store -* @tc.type: FUNC -*/ -HWTEST_F(RouteHeadHandlerImplTest, GetHeadDataSize_Test1, TestSize.Level0) -{ - DeviceInfo deviceInfo; - deviceInfo.osType = OH_OS_TYPE; - EXPECT_CALL(*deviceManagerAdapterMock, IsOHOSType(_)).WillRepeatedly(Return(true)); - EXPECT_CALL(*deviceManagerAdapterMock, GetDeviceInfo(_)).WillRepeatedly(Return(deviceInfo)); - - const DistributedDB::ExtendInfo info = { - .appId = "otherAppId", .storeId = "test_store", .userId = "100", .dstTarget = REMOTE_DEVICE - }; - auto sendHandler = RouteHeadHandlerImpl::Create(info); - ASSERT_NE(sendHandler, nullptr); - - CapMetaData capMetaData; - capMetaData.version = CapMetaData::CURRENT_VERSION; - capMetaData.deviceId = REMOTE_DEVICE; - auto capKey = CapMetaRow::GetKeyFor(REMOTE_DEVICE); - (void)MetaDataManager::GetInstance().SaveMeta({ capKey.begin(), capKey.end() }, capMetaData); - - bool result = false; - auto capMeta = UpgradeManager::GetInstance().GetCapability(REMOTE_DEVICE, result); - ASSERT_EQ(result, true); - ASSERT_EQ(capMeta.version, capMetaData.version); - ASSERT_EQ(capMeta.deviceId, REMOTE_DEVICE); - - uint32_t headSize = 0; - EXPECT_EQ(sendHandler->GetHeadDataSize(headSize), DBStatus::OK); - EXPECT_NE(headSize, 0); - -} diff --git a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp index d95efa56f..7be5d62b6 100644 --- a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp @@ -438,37 +438,28 @@ HWTEST_F(SessionManagerTest, GetHeadDataSize_Test4, TestSize.Level1) * @tc.desc: test get udmf store * @tc.type: FUNC * @tc.require: - * @tc.author: illybyy */ -HWTEST_F(SessionManagerTest, PackAndUnPack05, TestSize.Level1) +HWTEST_F(SessionManagerTest, GetHeadDataSize_Test5, TestSize.Level0) { + DeviceInfo deviceInfo; + deviceInfo.osType = OH_OS_TYPE; + EXPECT_CALL(*deviceManagerAdapterMock, IsOHOSType(_)).WillRepeatedly(Return(true)); + EXPECT_CALL(*deviceManagerAdapterMock, GetDeviceInfo(_)).WillRepeatedly(Return(deviceInfo)); + const DistributedDB::ExtendInfo info = { .appId = "distributeddata", .storeId = "drag", .userId = "100", .dstTarget = PEER_DEVICE_ID }; auto sendHandler = RouteHeadHandlerImpl::Create(info); ASSERT_NE(sendHandler, nullptr); - CapMetaData capMetaData; - capMetaData.version = CapMetaData::INVALID_VERSION; - - auto peerCapMetaKey = CapMetaRow::GetKeyFor(PEER_DEVICE_ID); - MetaDataManager::GetInstance().SaveMeta({ peerCapMetaKey.begin(), peerCapMetaKey.end() }, capMetaData); - - - uint32_t routeHeadSize = 0; - sendHandler->GetHeadDataSize(routeHeadSize); - ASSERT_NE(routeHeadSize, 0); - std::unique_ptr data = std::make_unique(routeHeadSize); - sendHandler->FillHeadData(data.get(), routeHeadSize, routeHeadSize); - - std::vector users; - auto recvHandler = RouteHeadHandlerImpl::Create({}); - ASSERT_NE(recvHandler, nullptr); - uint32_t parseSize = 0; - std::string device = "from_device"; - recvHandler->ParseHeadDataLen(data.get(), routeHeadSize, parseSize, device); - EXPECT_EQ(routeHeadSize, parseSize); + capMetaData.version = CapMetaData::CURRENT_VERSION; + EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) + .WillRepeatedly(DoAll(SetArgReferee<1>(capMetaData), Return(true))); + uint32_t headSize = 0; + auto status = sendHandler->GetHeadDataSize(headSize); + EXPECT_EQ(status, DistributedDB::OK); + EXPECT_EQ(headSize, 0); } /** * @tc.name: ParseHeadDataUserTest001 diff --git a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp index 1910cc7cd..4a44b8890 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp @@ -280,6 +280,31 @@ HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level1) ASSERT_EQ(sizeAfter, 0); } +/** +* @tc.name: TransferToEntriesIfNeedTest001 +* @tc.desc: TransferToEntriesIfNeed test +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level1) +{ + UnifiedData data; + QueryOption query; + auto record1 = std::make_shared(); + auto record2 = std::make_shared(); + data.AddRecord(record1); + data.AddRecord(record2); + auto properties = std::make_shared(); + properties->tag = "records_to_entries_data_format"; + data.SetProperties(properties); + query.tokenId = 1; + UdmfServiceImpl udmfServiceImpl; + udmfServiceImpl.TransferToEntriesIfNeed(query, data); + EXPECT_TRUE(data.IsNeedTransferToEntries()); + int recordSize = 2; + EXPECT_EQ(data.GetRecords().size(), recordSize); +} + /** * @tc.name: SaveMetaData001 * @tc.desc: Abnormal testcase of GetRuntime -- Gitee From edea6145baa079cbe1469a4cfbd2ff7d5ac66782 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sun, 8 Jun 2025 18:59:35 +0800 Subject: [PATCH 15/22] add test case Signed-off-by: wanghuajian-6 --- .../service/test/BUILD.gn | 3 + .../test/udmf_service_impl_mock_test.cpp | 5 +- .../service/test/udmf_service_impl_test.cpp | 60 ++++++++--------- .../service/udmf/udmf_service_impl.cpp | 67 ++++++++++--------- .../service/udmf/udmf_service_impl.h | 4 +- 5 files changed, 70 insertions(+), 69 deletions(-) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 613b32c08..1c74ca3a6 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1179,6 +1179,7 @@ ohos_unittest("UdmfServiceImplTest") { "ipc:ipc_core", "kv_store:distributeddata_inner", "kv_store:distributeddb", + "kv_store:distributeddata_mgr", "openssl:libcrypto_shared", "samgr:samgr_proxy", "safwk:system_ability_fwk", @@ -1245,8 +1246,10 @@ ohos_unittest("UdmfServiceImplMockTest") { "cJSON:cjson", "kv_store:distributeddata_inner", "kv_store:distributeddb", + "kv_store:distributeddata_mgr", "relational_store:native_rdb", "samgr:samgr_proxy", + "safwk:system_ability_fwk", "udmf:udmf_client", ] } diff --git a/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp index 9143f0ba6..83584033d 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "metadata/meta_data_manager.h" #define LOG_TAG "UdmfServiceImplTest" #include "udmf_service_impl.h" #include "gtest/gtest.h" @@ -172,5 +171,5 @@ HWTEST_F(UdmfServiceImplTest, ResolveAutoLaunchTest001, TestSize.Level0) ret = udmfServiceImpl->ResolveAutoLaunch(identifier, param); EXPECT_EQ(ret, UDMF::E_NOT_FOUND); } -} // DistributedDataTest -}; \ No newline at end of file +}; // DistributedDataTest +}; // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp index 4a44b8890..9170eb6e5 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp @@ -13,9 +13,7 @@ * limitations under the License. */ -#include "error_code.h" #define LOG_TAG "UdmfServiceImplTest" -#include #include "udmf_service_impl.h" #include "accesstoken_kit.h" #include "bootstrap.h" @@ -86,12 +84,7 @@ public: void SetUp(){}; void TearDown(){}; - const uint32_t MAX_KEY_SIZE = 1024; - const uint32_t MAX_VALUE_SIZE = 4 * 1024 * 1024; const std::string STORE_ID = "drag"; - const std::string KEY_PREFIX = "TEST_"; - const std::string EMPTY_DEVICE_ID = ""; - static constexpr size_t tempUdataRecordSize = 1; }; /** @@ -280,31 +273,6 @@ HWTEST_F(UdmfServiceImplTest, OnUserChangeTest001, TestSize.Level1) ASSERT_EQ(sizeAfter, 0); } -/** -* @tc.name: TransferToEntriesIfNeedTest001 -* @tc.desc: TransferToEntriesIfNeed test -* @tc.type: FUNC -* @tc.require: -*/ -HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level1) -{ - UnifiedData data; - QueryOption query; - auto record1 = std::make_shared(); - auto record2 = std::make_shared(); - data.AddRecord(record1); - data.AddRecord(record2); - auto properties = std::make_shared(); - properties->tag = "records_to_entries_data_format"; - data.SetProperties(properties); - query.tokenId = 1; - UdmfServiceImpl udmfServiceImpl; - udmfServiceImpl.TransferToEntriesIfNeed(query, data); - EXPECT_TRUE(data.IsNeedTransferToEntries()); - int recordSize = 2; - EXPECT_EQ(data.GetRecords().size(), recordSize); -} - /** * @tc.name: SaveMetaData001 * @tc.desc: Abnormal testcase of GetRuntime @@ -343,7 +311,7 @@ HWTEST_F(UdmfServiceImplTest, SyncTest001, TestSize.Level0) /** * @tc.name: ResolveAutoLaunch001 -* @tc.desc: +* @tc.desc: test ResolveAutoLaunch * @tc.type: FUNC * @tc.require: */ @@ -363,5 +331,31 @@ HWTEST_F(UdmfServiceImplTest, ResolveAutoLaunch001, TestSize.Level0) auto ret = udmfServiceImpl->ResolveAutoLaunch(identifier, param); EXPECT_EQ(ret, UDMF::E_OK); } + +/** +* @tc.name: TransferToEntriesIfNeedTest001 +* @tc.desc: TransferToEntriesIfNeed test +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level1) +{ + UnifiedData data; + QueryOption query; + auto record1 = std::make_shared(); + auto record2 = std::make_shared(); + data.AddRecord(record1); + data.AddRecord(record2); + auto properties = std::make_shared(); + properties->tag = "records_to_entries_data_format"; + data.SetProperties(properties); + query.tokenId = 1; + UdmfServiceImpl udmfServiceImpl; + udmfServiceImpl.TransferToEntriesIfNeed(query, data); + EXPECT_TRUE(data.IsNeedTransferToEntries()); + int recordSize = 2; + EXPECT_EQ(data.GetRecords().size(), recordSize); +} + }; // namespace DistributedDataTest }; // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index f06d34e64..c35a21ef7 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -573,6 +573,11 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vector &devices) +{ auto store = StoreCache::GetInstance().GetStore(key.intention); if (store == nullptr) { RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), @@ -596,13 +601,13 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vectorGetUserByToken(IPCSkeleton::GetCallingFullTokenID()); StoreMetaData meta = StoreMetaData(std::to_string(id), Bootstrap::GetInstance().GetProcessLabel(), key.intention); auto uuids = DmAdapter::GetInstance().ToUUID(devices); - if (IsNeedMetaSync(meta, uuids) && !MetaDataManager::GetInstance().Sync(uuids, [devices, callback, store] - (auto &results) { + if (IsNeedMetaSync(meta, uuids) && !MetaDataManager::GetInstance().Sync(uuids, + [devices, callback, store] (auto &results) { if (store->Sync(devices, callback) != E_OK) { ZLOGE("Store sync failed"); RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); - } + } })) { ZLOGW("bundleName:%{public}s, meta sync failed", key.bundleName.c_str()); } @@ -615,6 +620,34 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vector &uuids) +{ + using namespace OHOS::DistributedData; + bool isAfterMeta = false; + for (const auto &uuid : uuids) { + auto metaData = meta; + metaData.deviceId = uuid; + CapMetaData capMeta; + auto capKey = CapMetaRow::GetKeyFor(uuid); + if (!MetaDataManager::GetInstance().LoadMeta(std::string(capKey.begin(), capKey.end()), capMeta) || + !MetaDataManager::GetInstance().LoadMeta(metaData.GetKey(), metaData)) { + isAfterMeta = true; + break; + } + auto [exist, mask] = DeviceMatrix::GetInstance().GetRemoteMask(uuid); + if ((mask & DeviceMatrix::META_STORE_MASK) == DeviceMatrix::META_STORE_MASK) { + isAfterMeta = true; + break; + } + auto [existLocal, localMask] = DeviceMatrix::GetInstance().GetMask(uuid); + if ((localMask & DeviceMatrix::META_STORE_MASK) == DeviceMatrix::META_STORE_MASK) { + isAfterMeta = true; + break; + } + } + return isAfterMeta; +} + int32_t UdmfServiceImpl::IsRemoteData(const QueryOption &query, bool &result) { UnifiedKey key(query.key); @@ -1149,33 +1182,5 @@ int32_t UdmfServiceImpl::GetDataIfAvailable(const std::string &key, const DataLo dataLoadCallback_.Erase(key); return E_OK; } - -bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vector &uuids) -{ - using namespace OHOS::DistributedData; - bool isAfterMeta = false; - for (const auto &uuid : uuids) { - auto metaData = meta; - metaData.deviceId = uuid; - CapMetaData capMeta; - auto capKey = CapMetaRow::GetKeyFor(uuid); - if (!MetaDataManager::GetInstance().LoadMeta(std::string(capKey.begin(), capKey.end()), capMeta) || - !MetaDataManager::GetInstance().LoadMeta(metaData.GetKey(), metaData)) { - isAfterMeta = true; - break; - } - auto [exist, mask] = DeviceMatrix::GetInstance().GetRemoteMask(uuid); - if ((mask & DeviceMatrix::META_STORE_MASK) == DeviceMatrix::META_STORE_MASK) { - isAfterMeta = true; - break; - } - auto [existLocal, localMask] = DeviceMatrix::GetInstance().GetMask(uuid); - if ((localMask & DeviceMatrix::META_STORE_MASK) == DeviceMatrix::META_STORE_MASK) { - isAfterMeta = true; - break; - } - } - return isAfterMeta; -} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.h b/services/distributeddataservice/service/udmf/udmf_service_impl.h index e70b7e0c6..25ed32fb3 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.h +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.h @@ -56,6 +56,8 @@ public: int32_t GetDataIfAvailable(const std::string &key, const DataLoadInfo &dataLoadInfo, sptr iUdmfNotifier, std::shared_ptr unifiedData) override; private: + bool IsNeedMetaSync(const DistributedData::StoreMetaData &meta, const std::vector &uuids); + int32_t StoreSync(const UnifiedKey &key, const QueryOption &query, const std::vector &devices); int32_t SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key); int32_t RetrieveData(const QueryOption &query, UnifiedData &unifiedData); int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); @@ -77,8 +79,6 @@ private: bool IsFileMangerIntention(const std::string &intention); std::string FindIntentionMap(const Intention &queryintention); bool IsValidOptionsNonDrag(UnifiedKey &key, const std::string &intention); - bool IsNeedMetaSync(const DistributedData::StoreMetaData &meta, const std::vector &uuids); - class Factory { public: Factory(); -- Gitee From 8eba67c7436d6b4433d257a9b5940ac24ab2d502 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sun, 8 Jun 2025 19:07:47 +0800 Subject: [PATCH 16/22] add test case Signed-off-by: wanghuajian-6 --- .../service/test/udmf_service_impl_test.cpp | 2 +- .../service/udmf/udmf_service_impl.cpp | 15 +++++++++++++++ .../service/udmf/udmf_service_impl.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp index 30f4470da..bcb18a864 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_test.cpp @@ -356,7 +356,7 @@ HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level1) int recordSize = 2; EXPECT_EQ(data.GetRecords().size(), recordSize); } - +/** * @tc.name: IsValidInput001 * @tc.desc: invalid unifiedData * @tc.type: FUNC diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index 18d720eec..db5d7e1b4 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -1177,5 +1177,20 @@ int32_t UdmfServiceImpl::GetDataIfAvailable(const std::string &key, const DataLo dataLoadCallback_.Erase(key); return E_OK; } + +bool UdmfServiceImpl::IsValidInput(const QueryOption &query, UnifiedData &unifiedData, UnifiedKey &key) +{ + if (!unifiedData.IsValid() || !key.IsValid()) { + ZLOGE("Data or key is invalid, key = %{public}s", query.key.c_str()); + return false; + } + std::string intention = FindIntentionMap(query.intention); + if (!IsValidOptionsNonDrag(key, intention) || key.intention != UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB)) { + ZLOGE("Invalid params: key.intention = %{public}s, intention = %{public}s", + key.intention.c_str(), intention.c_str()); + return false; + } + return true; +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.h b/services/distributeddataservice/service/udmf/udmf_service_impl.h index 25ed32fb3..8f366463f 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.h +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.h @@ -79,6 +79,7 @@ private: bool IsFileMangerIntention(const std::string &intention); std::string FindIntentionMap(const Intention &queryintention); bool IsValidOptionsNonDrag(UnifiedKey &key, const std::string &intention); + bool IsValidInput(const QueryOption &query, UnifiedData &unifiedData, UnifiedKey &key); class Factory { public: Factory(); -- Gitee From 34f8569024bbe5536550f58d2790338e212c9b18 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Sun, 8 Jun 2025 21:21:46 +0800 Subject: [PATCH 17/22] add test case Signed-off-by: wanghuajian-6 --- .../service/test/udmf_service_impl_mock_test.cpp | 2 +- .../service/udmf/udmf_service_impl.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp index 83584033d..f2f958a8e 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp @@ -46,7 +46,7 @@ public: void SetUp() {} void TearDown() {} }; -void UdmfServiceImplTest::SetUpTestCase() +void UdmfServiceImplTest::SetUpTestCase() { accTokenMock = std::make_shared(); BAccessTokenKit::accessTokenkit = accTokenMock; diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index db5d7e1b4..1ceb45cc8 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -578,7 +578,8 @@ int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vector &devices) +int32_t UdmfServiceImpl::StoreSync(const UnifiedKey &key, const QueryOption &query, + const std::vector &devices) { auto store = StoreCache::GetInstance().GetStore(key.intention); if (store == nullptr) { @@ -609,7 +610,7 @@ int32_t UdmfServiceImpl::StoreSync(const UnifiedKey &key, const QueryOption &que ZLOGE("Store sync failed"); RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); - } + } })) { ZLOGW("bundleName:%{public}s, meta sync failed", key.bundleName.c_str()); } -- Gitee From 75e91899e641db0f2f577cee1ace8702752a3475 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Mon, 9 Jun 2025 11:41:13 +0800 Subject: [PATCH 18/22] add test case Signed-off-by: wanghuajian-6 --- .../distributeddataservice/app/test/BUILD.gn | 101 ++++++++ .../unittest/route_head_handler_impl_test.cpp | 241 ++++++++++++++++++ .../test/udmf_service_impl_mock_test.cpp | 79 ++---- 3 files changed, 368 insertions(+), 53 deletions(-) create mode 100644 services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index bccc0a525..61b270ec5 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -375,6 +375,106 @@ ohos_unittest("UpgradeManagerTest") { part_name = "datamgr_service" } +ohos_unittest("RouteHeadHandlerImplTest") { + module_out_path = module_output_path + + include_dirs = [ + "${data_service_path}/adapter/include/permission", + "${data_service_path}/adapter/include/account", + "${data_service_path}/adapter/include", + "${data_service_path}/adapter/include/utils", + "${data_service_path}/framework/include", + "${data_service_path}/service/bootstrap/include", + "${data_service_path}/service/common", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/data_share/common", + "${data_service_path}/service/directory/include", + "${data_service_path}/service/permission/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/app/src", + "${data_service_path}/app/src/session_manager", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/test/mock", + "../include", + "../src", + "../src/security", + "unittest", + "../src/installer", + "../../service/backup/include", + "../../../../interfaces/innerkits/distributeddata", + "../../service/dumper/include", + "${data_service_path}/adapter/include/communicator", + ] + + sources = [ + "../src/kvstore_meta_manager.cpp", + "../src/session_manager/route_head_handler_impl.cpp", + "../src/session_manager/session_manager.cpp", + "../src/session_manager/upgrade_manager.cpp", + "unittest/route_head_handler_impl_test.cpp", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${datamgr_service_path}/cfi_blocklist.txt" + } + + cflags_cc = [ "-DUT_TEST" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "dataclassification:data_transit_mgr", + "device_auth:deviceauth_sdk", + "device_manager:devicemanagersdk", + "file_api:securitylabel", + "googletest:gmock", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "cJSON:cjson", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (datamgr_service_power) { + external_deps += [ + "battery_manager:batterysrv_client", + "power_manager:powermgr_client", + ] + } + + deps = [ + "${data_service_path}/adapter/utils:distributeddata_utils", + "${data_service_path}/app/src/checker:distributeddata_checker", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service:distributeddatasvc", + "${data_service_path}/service/test/mock:distributeddata_mock_static", + ] + + cflags = [ + "-Werror", + "-Dprivate=public", + "-Dprotected=public", + ] + ldflags = [ "-Wl,--whole-archive" ] + defines = [ + "TEST_ON_DEVICE", + "OPENSSL_SUPPRESS_DEPRECATED", + ] + + part_name = "datamgr_service" +} + ############################################################################### group("unittest") { @@ -387,5 +487,6 @@ group("unittest") { ":KvStoreDataServiceTest", ":SessionManagerTest", ":UpgradeManagerTest", + ":RouteHeadHandlerImplTest", ] } \ No newline at end of file diff --git a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp new file mode 100644 index 000000000..60b47021d --- /dev/null +++ b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp @@ -0,0 +1,241 @@ +/* + * 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 "session_manager/session_manager.h" + +#include + +#include "accesstoken_kit.h" +#include "account_delegate_mock.h" +#include "auth_delegate_mock.h" +#include "bootstrap.h" +#include "device_manager_adapter.h" +#include "device_manager_adapter_mock.h" +#include "gtest/gtest.h" +#include +#include "meta_data_manager_mock.h" +#include "metadata/meta_data_manager.h" +#include "metadata/store_meta_data.h" +#include "nativetoken_kit.h" +#include "session_manager/route_head_handler_impl.h" +#include "session_manager/upgrade_manager.h" +#include "token_setproc.h" +#include "user_delegate.h" +#include "user_delegate_mock.h" +#include "utils/endian_converter.h" + +namespace { +using namespace testing; +using namespace testing::ext; +using namespace OHOS::DistributedKv; +using namespace OHOS::DistributedData; +using namespace DistributedDB; +using namespace OHOS; +using namespace OHOS::Security::AccessToken; +using DeviceInfo = OHOS::AppDistributedKv::DeviceInfo; +using UserInfo = DistributedDB::UserInfo; +constexpr const char *PEER_DEVICE_ID = "PEER_DEVICE_ID"; +constexpr const char *DDMS = "distributeddata"; +constexpr const char *META_DB = "service_meta"; +constexpr const char *DRAG = "drag"; +constexpr const char *OTHER_APP_ID = "test_app_id"; +constexpr const char *USER_ID = "100"; +static constexpr int32_t OH_OS_TYPE = 10; + +void GrantPermissionNative() +{ + const char **perms = new const char *[2]; + perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; + perms[1] = "ohos.permission.ACCESS_SERVICE_DM"; + TokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 2, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "distributed_data_test", + .aplStr = "system_basic", + }; + uint64_t tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + AccessTokenKit::ReloadNativeTokenInfo(); + delete[] perms; +} + +class RouteHeadHandlerImplTest : public testing::Test { +public: + static void SetUpTestCase() + { + GrantPermissionNative(); + deviceManagerAdapterMock = std::make_shared(); + BDeviceManagerAdapter::deviceManagerAdapter = deviceManagerAdapterMock; + metaDataManagerMock = std::make_shared(); + BMetaDataManager::metaDataManager = metaDataManagerMock; + metaDataMock = std::make_shared>(); + BMetaData::metaDataManager = metaDataMock; + userDelegateMock = std::make_shared(); + BUserDelegate::userDelegate = userDelegateMock; + } + static void TearDownTestCase() + { + deviceManagerAdapterMock = nullptr; + BDeviceManagerAdapter::deviceManagerAdapter = nullptr; + metaDataManagerMock = nullptr; + BMetaDataManager::metaDataManager = nullptr; + metaDataMock = nullptr; + BMetaData::metaDataManager = nullptr; + userDelegateMock = nullptr; + BUserDelegate::userDelegate = nullptr; + } + void SetUp(){}; + void TearDown(){}; + static inline std::shared_ptr deviceManagerAdapterMock = nullptr; + static inline std::shared_ptr metaDataManagerMock = nullptr; + static inline std::shared_ptr> metaDataMock = nullptr; + static inline std::shared_ptr userDelegateMock = nullptr; +private: + void GetEmptyHeadDataLen(const DistributedDB::ExtendInfo& info); + void ParseEmptyHeadDataLen(const DistributedDB::ExtendInfo& info); +}; + +void RouteHeadHandlerImplTest::GetEmptyHeadDataLen(const DistributedDB::ExtendInfo& info) +{ + DeviceInfo deviceInfo; + deviceInfo.osType = OH_OS_TYPE; + EXPECT_CALL(*deviceManagerAdapterMock, IsOHOSType(_)).WillRepeatedly(Return(true)); + EXPECT_CALL(*deviceManagerAdapterMock, GetDeviceInfo(_)).WillRepeatedly(Return(deviceInfo)); + + auto sendHandler = RouteHeadHandlerImpl::Create(info); + ASSERT_NE(sendHandler, nullptr); + + CapMetaData capMetaData; + capMetaData.version = CapMetaData::UDMF_AND_OBJECT_VERSION; + EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) + .WillRepeatedly(DoAll(SetArgReferee<1>(capMetaData), Return(true))); + uint32_t headSize = 0; + auto status = sendHandler->GetHeadDataSize(headSize); + EXPECT_EQ(status, DistributedDB::OK); + EXPECT_EQ(headSize, 0); +} + +void RouteHeadHandlerImplTest::ParseEmptyHeadDataLen(const DistributedDB::ExtendInfo& info) +{ + DeviceInfo deviceInfo; + deviceInfo.osType = OH_OS_TYPE; + EXPECT_CALL(*deviceManagerAdapterMock, IsOHOSType(_)).WillRepeatedly(Return(true)); + EXPECT_CALL(*deviceManagerAdapterMock, GetDeviceInfo(_)).WillRepeatedly(Return(deviceInfo)); + + auto recvHandler = RouteHeadHandlerImpl::Create(info); + ASSERT_NE(recvHandler, nullptr); + + CapMetaData capMetaData; + capMetaData.version = CapMetaData::UDMF_AND_OBJECT_VERSION; + EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) + .WillRepeatedly(DoAll(SetArgReferee<1>(capMetaData), Return(true))); + + uint32_t routeHeadSize = 0; + std::unique_ptr data = std::make_unique(routeHeadSize); + uint32_t parseSize = 0; + auto status = recvHandler->ParseHeadDataLen(data.get(), routeHeadSize, parseSize, PEER_DEVICE_ID); + EXPECT_EQ(status, false); + EXPECT_EQ(parseSize, routeHeadSize); +} + +/** + * @tc.name: PackAndUnPack05 + * @tc.desc: test get udmf store + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test1, TestSize.Level0) +{ + const DistributedDB::ExtendInfo info = { + .appId = DDMS, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + }; + GetEmptyHeadDataLen(info); +} + +/** + * @tc.name: PackAndUnPack05 + * @tc.desc: test get udmf store + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test2, TestSize.Level0) +{ + const DistributedDB::ExtendInfo info = { + .appId = DDMS, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + }; + GetEmptyHeadDataLen(info); +} + +/** + * @tc.name: PackAndUnPack05 + * @tc.desc: test get udmf store + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test1, TestSize.Level0) +{ + const DistributedDB::ExtendInfo info = { + .appId = DDMS, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + }; + GetEmptyHeadDataLen(info); +} + +/** + * @tc.name: PackAndUnPack05 + * @tc.desc: test get udmf store + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test2, TestSize.Level0) +{ + const DistributedDB::ExtendInfo info = { + .appId = DDMS, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + }; + GetEmptyHeadDataLen(info); +} + +/** + * @tc.name: PackAndUnPack05 + * @tc.desc: test get udmf store + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test3, TestSize.Level0) +{ + const DistributedDB::ExtendInfo info = { + .appId = OTHER_APP_ID, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + }; + GetEmptyHeadDataLen(info); +} + +/** + * @tc.name: PackAndUnPack05 + * @tc.desc: test get udmf store + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test4, TestSize.Level0) +{ + const DistributedDB::ExtendInfo info = { + .appId = OTHER_APP_ID, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + }; + GetEmptyHeadDataLen(info); +} + +} // namespace \ No newline at end of file diff --git a/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp index f2f958a8e..c782a4346 100644 --- a/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp +++ b/services/distributeddataservice/service/test/udmf_service_impl_mock_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#define LOG_TAG "UdmfServiceImplTest" +#define LOG_TAG "UdmfServiceImplMockTest" #include "udmf_service_impl.h" #include "gtest/gtest.h" #include "error_code.h" @@ -33,70 +33,43 @@ using namespace OHOS::Security::AccessToken; using namespace OHOS::UDMF; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using namespace testing::ext; +using namespace testing; namespace OHOS::Test { namespace DistributedDataTest { -class UdmfServiceImplTest : public testing::Test { +class UdmfServiceImplMockTest : public testing::Test { public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); + static void SetUpTestCase(void) + { + accTokenMock = std::make_shared(); + BAccessTokenKit::accessTokenkit = accTokenMock; + metaDataManagerMock = std::make_shared(); + BMetaDataManager::metaDataManager = metaDataManagerMock; + metaDataMock = std::make_shared>(); + BMetaData::metaDataManager = metaDataMock; + } + static void TearDownTestCase(void) + { + accTokenMock = nullptr; + BAccessTokenKit::accessTokenkit = nullptr; + metaDataManagerMock = nullptr; + BMetaDataManager::metaDataManager = nullptr; + metaDataMock = nullptr; + BMetaData::metaDataManager = nullptr; + } static inline std::shared_ptr accTokenMock = nullptr; static inline std::shared_ptr metaDataManagerMock = nullptr; static inline std::shared_ptr> metaDataMock = nullptr; - void SetUp() {} - void TearDown() {} + void SetUp() {}; + void TearDown() {}; }; -void UdmfServiceImplTest::SetUpTestCase() -{ - accTokenMock = std::make_shared(); - BAccessTokenKit::accessTokenkit = accTokenMock; - metaDataManagerMock = std::make_shared(); - BMetaDataManager::metaDataManager = metaDataManagerMock; - metaDataMock = std::make_shared>(); - BMetaData::metaDataManager = metaDataMock; -} - -void UdmfServiceImplTest::TearDownTestCase(void) -{ - accTokenMock = nullptr; - BAccessTokenKit::accessTokenkit = nullptr; - metaDataManagerMock = nullptr; - BMetaDataManager::metaDataManager = nullptr; - metaDataMock = nullptr; - BMetaData::metaDataManager = nullptr; -} - -/** -* @tc.name: TransferToEntriesIfNeedTest001 -* @tc.desc: TransferToEntriesIfNeed test -* @tc.type: FUNC -* @tc.require: -*/ -HWTEST_F(UdmfServiceImplTest, TransferToEntriesIfNeedTest001, TestSize.Level0) -{ - UnifiedData data; - QueryOption query; - auto record1 = std::make_shared(); - auto record2 = std::make_shared(); - data.AddRecord(record1); - data.AddRecord(record2); - auto properties = std::make_shared(); - properties->tag = "records_to_entries_data_format"; - data.SetProperties(properties); - query.tokenId = 1; - UdmfServiceImpl udmfServiceImpl; - udmfServiceImpl.TransferToEntriesIfNeed(query, data); - EXPECT_TRUE(data.IsNeedTransferToEntries()); - int recordSize = 2; - EXPECT_EQ(data.GetRecords().size(), recordSize); -} /** * @tc.name: IsNeedMetaSyncTest001 * @tc.desc: IsNeedMetaSync test * @tc.type: FUNC */ -HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest001, TestSize.Level0) +HWTEST_F(UdmfServiceImplMockTest, IsNeedMetaSyncTest001, TestSize.Level0) { UdmfServiceImpl udmfServiceImpl; StoreMetaData meta = StoreMetaData("100", "distributeddata", "drag"); @@ -132,7 +105,7 @@ HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest001, TestSize.Level0) * @tc.desc: IsNeedMetaSync test matrix mask * @tc.type: FUNC */ -HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest002, TestSize.Level0) +HWTEST_F(UdmfServiceImplMockTest, IsNeedMetaSyncTest002, TestSize.Level0) { QueryOption query; query.key = "test_key"; @@ -155,7 +128,7 @@ HWTEST_F(UdmfServiceImplTest, IsNeedMetaSyncTest002, TestSize.Level0) * @tc.desc: ResolveAutoLaunch test. * @tc.type: FUNC */ -HWTEST_F(UdmfServiceImplTest, ResolveAutoLaunchTest001, TestSize.Level0) +HWTEST_F(UdmfServiceImplMockTest, ResolveAutoLaunchTest001, TestSize.Level0) { auto store = StoreCache::GetInstance().GetStore("drag"); auto ret = store->Init(); -- Gitee From 93d4e127009b919a4a991d4b1b49cd1b28e21711 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Mon, 9 Jun 2025 11:43:24 +0800 Subject: [PATCH 19/22] add test case Signed-off-by: wanghuajian-6 --- .../test/unittest/session_manager_test.cpp | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp index 7be5d62b6..b336e74fe 100644 --- a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp @@ -348,6 +348,7 @@ HWTEST_F(SessionManagerTest, GetHeadDataSize_Test1, TestSize.Level1) RouteHeadHandlerImpl routeHeadHandlerImpl(info); uint32_t headSize = 0; routeHeadHandlerImpl.appId_ = Bootstrap::GetInstance().GetProcessLabel(); + routeHeadHandlerImpl.storeId_ = Bootstrap::GetInstance().GetMetaDBName(); auto status = routeHeadHandlerImpl.GetHeadDataSize(headSize); EXPECT_EQ(status, DistributedDB::OK); EXPECT_EQ(headSize, 0); @@ -432,35 +433,6 @@ HWTEST_F(SessionManagerTest, GetHeadDataSize_Test4, TestSize.Level1) status = sendHandler->FillHeadData(data.get(), routeHeadSize, routeHeadSize); EXPECT_EQ(status, DistributedDB::DB_ERROR); } - -/** - * @tc.name: PackAndUnPack05 - * @tc.desc: test get udmf store - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(SessionManagerTest, GetHeadDataSize_Test5, TestSize.Level0) -{ - DeviceInfo deviceInfo; - deviceInfo.osType = OH_OS_TYPE; - EXPECT_CALL(*deviceManagerAdapterMock, IsOHOSType(_)).WillRepeatedly(Return(true)); - EXPECT_CALL(*deviceManagerAdapterMock, GetDeviceInfo(_)).WillRepeatedly(Return(deviceInfo)); - - const DistributedDB::ExtendInfo info = { - .appId = "distributeddata", .storeId = "drag", .userId = "100", .dstTarget = PEER_DEVICE_ID - }; - auto sendHandler = RouteHeadHandlerImpl::Create(info); - ASSERT_NE(sendHandler, nullptr); - - CapMetaData capMetaData; - capMetaData.version = CapMetaData::CURRENT_VERSION; - EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) - .WillRepeatedly(DoAll(SetArgReferee<1>(capMetaData), Return(true))); - uint32_t headSize = 0; - auto status = sendHandler->GetHeadDataSize(headSize); - EXPECT_EQ(status, DistributedDB::OK); - EXPECT_EQ(headSize, 0); -} /** * @tc.name: ParseHeadDataUserTest001 * @tc.desc: test parse null data. -- Gitee From 431067977d3c1ecb3624d542ee0e38f7d8e62dfc Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Mon, 9 Jun 2025 11:47:21 +0800 Subject: [PATCH 20/22] add test case Signed-off-by: wanghuajian-6 --- .../unittest/route_head_handler_impl_test.cpp | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp index 60b47021d..aefb871e7 100644 --- a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp +++ b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp @@ -155,10 +155,9 @@ void RouteHeadHandlerImplTest::ParseEmptyHeadDataLen(const DistributedDB::Extend } /** - * @tc.name: PackAndUnPack05 + * @tc.name: GetEmptyHeadDataLen_Test1 * @tc.desc: test get udmf store * @tc.type: FUNC - * @tc.require: */ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test1, TestSize.Level0) { @@ -169,10 +168,9 @@ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test1, TestSize.Level0) } /** - * @tc.name: PackAndUnPack05 - * @tc.desc: test get udmf store + * @tc.name: GetEmptyHeadDataLen_Test2 + * @tc.desc: test meta db * @tc.type: FUNC - * @tc.require: */ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test2, TestSize.Level0) { @@ -183,10 +181,9 @@ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test2, TestSize.Level0) } /** - * @tc.name: PackAndUnPack05 + * @tc.name: ParseEmptyHeadDataLen_Test1 * @tc.desc: test get udmf store * @tc.type: FUNC - * @tc.require: */ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test1, TestSize.Level0) { @@ -197,10 +194,9 @@ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test1, TestSize.Level0) } /** - * @tc.name: PackAndUnPack05 - * @tc.desc: test get udmf store + * @tc.name: ParseEmptyHeadDataLen_Test2 + * @tc.desc: test get meta db * @tc.type: FUNC - * @tc.require: */ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test2, TestSize.Level0) { @@ -211,10 +207,9 @@ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test2, TestSize.Level0) } /** - * @tc.name: PackAndUnPack05 - * @tc.desc: test get udmf store + * @tc.name: ParseEmptyHeadDataLen_Test3 + * @tc.desc: test OTHER_APP_ID * @tc.type: FUNC - * @tc.require: */ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test3, TestSize.Level0) { @@ -225,10 +220,10 @@ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test3, TestSize.Level0) } /** - * @tc.name: PackAndUnPack05 - * @tc.desc: test get udmf store + * @tc.name: ParseEmptyHeadDataLen_Test4 + * @tc.desc: test get OTHER_APP_ID and meta db * @tc.type: FUNC - * @tc.require: + */ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test4, TestSize.Level0) { @@ -237,5 +232,4 @@ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test4, TestSize.Level0) }; GetEmptyHeadDataLen(info); } - } // namespace \ No newline at end of file -- Gitee From d255cb7b7e89262d4c583026d275ca6f9b3e7337 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Mon, 9 Jun 2025 12:49:54 +0800 Subject: [PATCH 21/22] add test case Signed-off-by: wanghuajian-6 --- .../app/test/unittest/route_head_handler_impl_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp index aefb871e7..722920f18 100644 --- a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp +++ b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp @@ -47,7 +47,7 @@ using namespace OHOS::Security::AccessToken; using DeviceInfo = OHOS::AppDistributedKv::DeviceInfo; using UserInfo = DistributedDB::UserInfo; constexpr const char *PEER_DEVICE_ID = "PEER_DEVICE_ID"; -constexpr const char *DDMS = "distributeddata"; +constexpr const char *DDMS_APP_ID = "distributeddata"; constexpr const char *META_DB = "service_meta"; constexpr const char *DRAG = "drag"; constexpr const char *OTHER_APP_ID = "test_app_id"; @@ -162,7 +162,7 @@ void RouteHeadHandlerImplTest::ParseEmptyHeadDataLen(const DistributedDB::Extend HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test1, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = DDMS_APP_ID, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } @@ -175,7 +175,7 @@ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test1, TestSize.Level0) HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test2, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = DDMS_APP_ID, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } @@ -188,7 +188,7 @@ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test2, TestSize.Level0) HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test1, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = DDMS_APP_ID, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } @@ -201,7 +201,7 @@ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test1, TestSize.Level0) HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test2, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = DDMS_APP_ID, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } -- Gitee From 174e30d35fef185c81fc4c9e0c0ca30934dbd6a2 Mon Sep 17 00:00:00 2001 From: wanghuajian-6 Date: Mon, 9 Jun 2025 15:56:19 +0800 Subject: [PATCH 22/22] fix codecheck Signed-off-by: wanghuajian-6 --- .../app/test/unittest/route_head_handler_impl_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp index 722920f18..905ce1606 100644 --- a/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp +++ b/services/distributeddataservice/app/test/unittest/route_head_handler_impl_test.cpp @@ -47,7 +47,7 @@ using namespace OHOS::Security::AccessToken; using DeviceInfo = OHOS::AppDistributedKv::DeviceInfo; using UserInfo = DistributedDB::UserInfo; constexpr const char *PEER_DEVICE_ID = "PEER_DEVICE_ID"; -constexpr const char *DDMS_APP_ID = "distributeddata"; +constexpr const char *PROCESSLABEL = "distributeddata"; constexpr const char *META_DB = "service_meta"; constexpr const char *DRAG = "drag"; constexpr const char *OTHER_APP_ID = "test_app_id"; @@ -162,7 +162,7 @@ void RouteHeadHandlerImplTest::ParseEmptyHeadDataLen(const DistributedDB::Extend HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test1, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS_APP_ID, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = PROCESSLABEL, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } @@ -175,7 +175,7 @@ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test1, TestSize.Level0) HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test2, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS_APP_ID, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = PROCESSLABEL, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } @@ -188,7 +188,7 @@ HWTEST_F(RouteHeadHandlerImplTest, GetEmptyHeadDataLen_Test2, TestSize.Level0) HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test1, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS_APP_ID, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = PROCESSLABEL, .storeId = DRAG, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } @@ -201,7 +201,7 @@ HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test1, TestSize.Level0) HWTEST_F(RouteHeadHandlerImplTest, ParseEmptyHeadDataLen_Test2, TestSize.Level0) { const DistributedDB::ExtendInfo info = { - .appId = DDMS_APP_ID, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID + .appId = PROCESSLABEL, .storeId = META_DB, .userId = USER_ID, .dstTarget = PEER_DEVICE_ID }; GetEmptyHeadDataLen(info); } -- Gitee