From b48ddcb6be0a9bf07c575075d40f8e070ff71485 Mon Sep 17 00:00:00 2001 From: ZhaoJinghui Date: Tue, 2 Sep 2025 20:58:37 +0800 Subject: [PATCH] diff sync Signed-off-by: ZhaoJinghui Change-Id: I50eefd43a335df42d863c4b980fc1ae316eb8abc --- .../app/src/kvstore_data_service.cpp | 8 +- .../app/src/kvstore_data_service.h | 2 +- .../service/rdb/rdb_query.h | 4 +- .../service/rdb/rdb_service_impl.cpp | 12 +- .../service/rdb/rdb_service_impl.h | 24 +-- .../fuzztest/rdbservicestub_fuzzer/BUILD.gn | 1 + .../service/test/rdb_asset_loader_test.cpp | 184 ++++++++++-------- .../service/test/rdb_general_store_test.cpp | 6 +- .../service/test/rdb_service_impl_test.cpp | 35 +++- 9 files changed, 155 insertions(+), 121 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index a9be1e0d0..3f5e7766e 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -87,10 +87,10 @@ constexpr const char* CLONE_KEY_ALIAS = "distributed_db_backup_key"; REGISTER_SYSTEM_ABILITY_BY_ID(KvStoreDataService, DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, true); constexpr char FOUNDATION_PROCESS_NAME[] = "foundation"; -constexpr int MAX_DOWNLOAD_ASSETS_COUNT = 50; -constexpr int MAX_DOWNLOAD_TASK = 5; constexpr int KEY_SIZE = 32; constexpr int AES_256_NONCE_SIZE = 32; +constexpr int MAX_DOWNLOAD_ASSETS_COUNT = 50; +constexpr int MAX_DOWNLOAD_TASK = 5; constexpr int MAX_CLIENT_DEATH_OBSERVER_SIZE = 16; KvStoreDataService::KvStoreDataService(bool runOnCreate) @@ -546,7 +546,7 @@ int32_t KvStoreDataService::OnBackup(MessageParcel &data, MessageParcel &reply) } std::vector KvStoreDataService::ReEncryptKey(const std::string &key, SecretKeyMetaData &secretKeyMeta, - const StoreMetaData &metaData, const std::vector &iv) + const std::vector &iv, const StoreMetaData &metaData) { if (!MetaDataManager::GetInstance().LoadMeta(key, secretKeyMeta, true)) { return {}; @@ -584,7 +584,7 @@ std::string KvStoreDataService::GetSecretKeyBackup(const std::vector ReEncryptKey(const std::string &key, SecretKeyMetaData &secretKeyMeta, - const StoreMetaData &metaData, const std::vector &iv); + const std::vector &iv, const StoreMetaData &metaData); bool ParseSecretKeyFile(MessageParcel &data, SecretKeyBackupData &backupData); diff --git a/services/distributeddataservice/service/rdb/rdb_query.h b/services/distributeddataservice/service/rdb/rdb_query.h index 94d9460f2..c420e2f63 100644 --- a/services/distributeddataservice/service/rdb/rdb_query.h +++ b/services/distributeddataservice/service/rdb/rdb_query.h @@ -100,10 +100,10 @@ private: &RdbQuery::LessThan, &RdbQuery::LessThanOrEqual, &RdbQuery::Distinct, + &RdbQuery::IndexedBy, &RdbQuery::NotContains, &RdbQuery::NotLike, - &RdbQuery::AssetsOnly, - &RdbQuery::IndexedBy + &RdbQuery::AssetsOnly }; static constexpr inline uint32_t DECIMAL_BASE = 10; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index c580433a9..b35baa64b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -19,7 +19,6 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "bootstrap.h" -#include "bundle_utils.h" #include "changeevent/remote_change_event.h" #include "checker/checker_manager.h" #include "cloud/change_event.h" @@ -437,8 +436,7 @@ std::pair> RdbServiceImpl::R return { RDB_ERROR, nullptr }; } std::vector devices = { DmAdapter::GetInstance().ToUUID(device) }; - if (IsNeedMetaSync(meta, devices) && !MetaDataManager::GetInstance().Sync( - devices, [](auto &results) {}, true)) { + if (IsNeedMetaSync(meta, devices) && !MetaDataManager::GetInstance().Sync(devices, [](auto &results) {}, true)) { ZLOGW("bundleName:%{public}s, storeName:%{public}s. meta sync failed", param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str()); } @@ -1000,7 +998,7 @@ int32_t RdbServiceImpl::AfterOpen(const RdbSyncerParam ¶m) if (param.isEncrypt_ && !param.password_.empty()) { SaveSecretKeyMeta(meta, param.password_); } - GetSchema(param); + GetCloudSchema(param); return RDB_OK; } @@ -1033,7 +1031,7 @@ int32_t RdbServiceImpl::ReportStatistic(const RdbSyncerParam& param, const RdbSt return RDB_OK; } -void RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) +void RdbServiceImpl::GetCloudSchema(const RdbSyncerParam ¶m) { if (executors_ != nullptr) { StoreInfo storeInfo; @@ -1239,7 +1237,7 @@ int RdbServiceImpl::DoAutoSync( rdbQuery.MakeQuery(table); std::vector onDevices = GetReuseDevice(devices, storeMetaData); if (onDevices.empty()) { - ZLOGE("autosync ondevices null, storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); + ZLOGE("autosync device null, storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); return; } auto complete = [this, rdbQuery, store, syncParam, async]( @@ -1848,7 +1846,7 @@ bool RdbServiceImpl::TryUpdateDeviceId(const RdbSyncerParam ¶m, const StoreM } auto errCode = store->UpdateDBStatus(); if (errCode != RDB_OK) { - ZLOGE("Update failed errCode %{public}d", errCode); + ZLOGE("update failed errCode %{public}d", errCode); return false; } } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 6db6dfa4b..9fea7bef1 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -196,6 +196,14 @@ private: DetailAsync GetCallbacks(uint32_t tokenId, const std::string &storeName); + bool IsValidAccess(const std::string& bundleName, const std::string& storeName); + + bool IsValidPath(const std::string& param); + + bool IsValidCustomDir(const std::string &customDir, int32_t upLimit); + + bool IsValidParam(const RdbSyncerParam ¶m); + std::shared_ptr GetStore(const RdbSyncerParam& param); std::shared_ptr GetStore(const StoreMetaData &storeMetaData); @@ -203,8 +211,8 @@ private: void OnAsyncComplete(uint32_t tokenId, pid_t pid, uint32_t seqNum, Details &&result); int32_t Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &old); - - void GetSchema(const RdbSyncerParam ¶m); + + void GetCloudSchema(const RdbSyncerParam ¶m); bool IsPostImmediately(const int32_t callingPid, const RdbNotifyConfig &rdbNotifyConfig, StoreInfo &storeInfo, DistributedData::DataChangeEvent::EventInfo &eventInfo, const std::string &storeName); @@ -213,14 +221,6 @@ private: void SaveLaunchInfo(StoreMetaData &meta); - static bool IsValidAccess(const std::string& bundleName, const std::string& storeName); - - static bool IsValidPath(const std::string& param); - - static bool IsValidCustomDir(const std::string &customDir, int32_t upLimit); - - static bool IsValidParam(const RdbSyncerParam ¶m); - static StoreMetaData GetStoreMetaData(const RdbSyncerParam ¶m); static std::pair LoadStoreMetaData(const RdbSyncerParam ¶m); @@ -261,12 +261,12 @@ private: static int32_t PostSearchEvent(int32_t evtId, const RdbSyncerParam& param, DistributedData::SetSearchableEvent::EventInfo &eventInfo); - static void UpdateMeta(const StoreMetaData &meta, const StoreMetaData &localMeta, AutoCache::Store store); - std::vector LoadSecretKey(const StoreMetaData &metaData, CryptoManager::SecretKeyType secretKeyType); void SaveSecretKeyMeta(const StoreMetaData &metaData, const std::vector &password); + static void UpdateMeta(const StoreMetaData &meta, const StoreMetaData &localMeta, AutoCache::Store store); + static Factory factory_; ConcurrentMap syncAgents_; std::shared_ptr executors_; diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn index 23fe264db..21c263489 100644 --- a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn @@ -80,6 +80,7 @@ ohos_fuzztest("RdbServiceStubFuzzTest") { "device_manager:devicemanagersdk", "hicollie:libhicollie", "hilog:libhilog", + "hisysevent:libhisysevent", "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", diff --git a/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp b/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp index a24357120..6a0638a70 100644 --- a/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp +++ b/services/distributeddataservice/service/test/rdb_asset_loader_test.cpp @@ -12,19 +12,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #define LOG_TAG "RdbAssetLoaderTest" #include "rdb_asset_loader.h" +#include "gtest/gtest.h" #include "log_print.h" -#include "object_snapshot.h" #include "rdb_notifier_proxy.h" #include "rdb_watcher.h" #include "store/cursor.h" #include "store/general_value.h" #include "store/general_watcher.h" -#include "gtest/gtest.h" - +#include "object_snapshot.h" using namespace OHOS; using namespace testing; using namespace testing::ext; @@ -259,28 +259,29 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent002, TestSize.Level0) } /** -@tc.name: PostEvent003 -@tc.desc: RdbAssetLoader PostEvent003 test -@tc.type: FUNC -@tc.require: -@tc.author: SQL +* @tc.name: PostEvent003 +* @tc.desc: RdbAssetLoader PostEvent003 test +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent003, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent003, TestSize.Level0) +{ DistributedData::Asset asset = { - .name = "", - .id = "", - .path = "", - .uri = "", - .modifyTime = "", - .createTime = "", - .size = "", - .hash = "", - .status = DistributedData::Asset::STATUS_NORMAL, + .name = "", + .id = "", + .path = "", + .uri = "", + .modifyTime = "", + .createTime = "", + .size = "", + .hash = "", + .status = DistributedData::Asset::STATUS_NORMAL, }; DistributedData::Assets assets; assets.push_back(asset); BindAssets bindAssets = nullptr; - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; std::set deleteAssets; @@ -290,13 +291,14 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent003, TestSize.Level0) { } /** -@tc.name: PostEvent004 -@tc.desc: RdbAssetLoader PostEvent004 test,snapshots_ can find data with a value of null -@tc.type: FUNC -@tc.require: -@tc.author: SQL +* @tc.name: PostEvent004 +* @tc.desc: RdbAssetLoader PostEvent004 test,snapshots_ can find data with a value of null +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent004, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent004, TestSize.Level0) +{ DistributedData::Asset asset = { .name = "", .id = "", @@ -312,7 +314,7 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent004, TestSize.Level0) { assets.push_back(asset); BindAssets bindAssets = std::make_shared>>(); bindAssets->insert({"PostEvent004", nullptr}); - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; std::set deleteAssets; @@ -322,18 +324,20 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent004, TestSize.Level0) { } /** -@tc.name: PostEvent005 -@tc.desc: RdbAssetLoader PostEvent005 test,snapshots_ can find data and the value is not null -@tc.type: FUNC -@tc.require: -@tc.author: SQL +* @tc.name: PostEvent005 +* @tc.desc: RdbAssetLoader PostEvent005 test,snapshots_ can find data and the value is not null +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent005, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent005, TestSize.Level0) +{ class ObjectSnapshotMock : public DistributedObject::ObjectSnapshot { public: - int32_t Download(Asset &asset) override { - hasDownload = true; - return 0; + int32_t Download(Asset& asset) override + { + hasDownload = true; + return 0; } bool hasDownload = false; }; @@ -353,23 +357,23 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent005, TestSize.Level0) { BindAssets bindAssets = std::make_shared>>(); auto objectSnapshotMock = std::make_shared(); bindAssets->insert({"PostEvent005", objectSnapshotMock}); - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; std::set deleteAssets; - rdbAssetLoader.PostEvent(DistributedData::AssetEvent::DOWNLOAD, assets, - skipAssets, deleteAssets); + rdbAssetLoader.PostEvent(DistributedData::AssetEvent::DOWNLOAD, assets, skipAssets, deleteAssets); EXPECT_EQ(objectSnapshotMock->hasDownload, true); } /** -@tc.name: PostEvent006 -@tc.desc: RdbAssetLoader PostEvent006 test,snapshots_ not found -@tc.type: FUNC -@tc.require: -@tc.author: SQL +* @tc.name: PostEvent006 +* @tc.desc: RdbAssetLoader PostEvent006 test,snapshots_ not found +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent006, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent006, TestSize.Level0) +{ DistributedData::Asset asset = { .name = "", .id = "", @@ -385,7 +389,7 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent006, TestSize.Level0) { assets.push_back(asset); BindAssets bindAssets = std::make_shared>>(); bindAssets->insert({"PostEvent006", std::make_shared()}); - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; std::set deleteAssets; @@ -395,18 +399,20 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent006, TestSize.Level0) { } /** -@tc.name: PostEvent007 -@tc.desc: RdbAssetLoader PostEvent007 test, Both deleteAssets and skipAssets can be found. -@tc.type: FUNC -@tc.require: -@tc.author: SQL +* @tc.name: PostEvent007 +* @tc.desc: RdbAssetLoader PostEvent007 test, Both deleteAssets and skipAssets can be found. +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent007, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent007, TestSize.Level0) +{ class ObjectSnapshotMock : public DistributedObject::ObjectSnapshot { public: - int32_t Downloaded(Asset &asset) override { - hasDownloaded = true; - return 0; + int32_t Downloaded(Asset& asset) override + { + hasDownloaded = true; + return 0; } bool hasDownloaded = false; }; @@ -426,7 +432,7 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent007, TestSize.Level0) { BindAssets bindAssets = std::make_shared>>(); auto objectSnapshotMock = std::make_shared(); bindAssets->insert({"PostEvent007", objectSnapshotMock}); - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; skipAssets.insert("PostEvent007"); @@ -437,18 +443,20 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent007, TestSize.Level0) { } /** -@tc.name: PostEvent008 -@tc.desc: RdbAssetLoader PostEvent008 test, Neither deleteAssets nor skipAssets can be found. -@tc.type: FUNC -@tc.require: -@tc.author: SQL +* @tc.name: PostEvent008 +* @tc.desc: RdbAssetLoader PostEvent008 test, Neither deleteAssets nor skipAssets can be found. +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent008, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent008, TestSize.Level0) +{ class ObjectSnapshotMock : public DistributedObject::ObjectSnapshot { public: - int32_t Downloaded(Asset &asset) override { - hasDownloaded = true; - return 0; + int32_t Downloaded(Asset& asset) override + { + hasDownloaded = true; + return 0; } bool hasDownloaded = false; }; @@ -468,27 +476,29 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent008, TestSize.Level0) { BindAssets bindAssets = std::make_shared>>(); auto objectSnapshotMock = std::make_shared(); bindAssets->insert({"PostEvent008", objectSnapshotMock}); - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; std::set deleteAssets; rdbAssetLoader.PostEvent(DistributedData::AssetEvent::UPLOAD, assets, skipAssets, deleteAssets); EXPECT_EQ(objectSnapshotMock->hasDownloaded, true); } -/** -@tc.name: PostEvent009 -@tc.desc: RdbAssetLoader PostEvent009 test, deleteAssets can be found, skipAssets cannot be found. -@tc.type: FUNC -@tc.require: -@tc.author: SQL +/** +* @tc.name: PostEvent009 +* @tc.desc: RdbAssetLoader PostEvent009 test, deleteAssets can be found, skipAssets cannot be found. +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent009, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent009, TestSize.Level0) +{ class ObjectSnapshotMock : public DistributedObject::ObjectSnapshot { public: - int32_t Downloaded(Asset &asset) override { - hasDownloaded = true; - return 0; + int32_t Downloaded(Asset& asset) override + { + hasDownloaded = true; + return 0; } bool hasDownloaded = false; }; @@ -508,7 +518,7 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent009, TestSize.Level0) { BindAssets bindAssets = std::make_shared>>(); auto objectSnapshotMock = std::make_shared(); bindAssets->insert({"PostEvent009", objectSnapshotMock}); - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; std::set deleteAssets; @@ -518,18 +528,20 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent009, TestSize.Level0) { } /** -@tc.name: PostEvent0010 -@tc.desc: RdbAssetLoader PostEvent0010 test, skipAssets can be found, deleteAssets cannot be found. -@tc.type: FUNC -@tc.require: -@tc.author: SQL +* @tc.name: PostEvent0010 +* @tc.desc: RdbAssetLoader PostEvent0010 test, skipAssets can be found, deleteAssets cannot be found. +* @tc.type: FUNC +* @tc.require: +* @tc.author: SQL */ -HWTEST_F(RdbAssetLoaderTest, PostEvent0010, TestSize.Level0) { +HWTEST_F(RdbAssetLoaderTest, PostEvent0010, TestSize.Level0) +{ class ObjectSnapshotMock : public DistributedObject::ObjectSnapshot { public: - int32_t Downloaded(Asset &asset) override { - hasDownloaded = true; - return 0; + int32_t Downloaded(Asset& asset) override + { + hasDownloaded = true; + return 0; } bool hasDownloaded = false; }; @@ -549,7 +561,7 @@ HWTEST_F(RdbAssetLoaderTest, PostEvent0010, TestSize.Level0) { BindAssets bindAssets = std::make_shared>>(); auto objectSnapshotMock = std::make_shared(); bindAssets->insert({"PostEvent0010", objectSnapshotMock}); - std::shared_ptr assetLoader = std::make_shared(); + std::shared_ptr assetLoader = std::make_shared(); DistributedRdb::RdbAssetLoader rdbAssetLoader(assetLoader, bindAssets); std::set skipAssets; skipAssets.insert("PostEvent0010"); diff --git a/services/distributeddataservice/service/test/rdb_general_store_test.cpp b/services/distributeddataservice/service/test/rdb_general_store_test.cpp index 6a2dbf2a1..295767794 100644 --- a/services/distributeddataservice/service/test/rdb_general_store_test.cpp +++ b/services/distributeddataservice/service/test/rdb_general_store_test.cpp @@ -137,9 +137,9 @@ HWTEST_F(RdbGeneralStoreTest, BindSnapshots002, TestSize.Level1) } /** -@tc.name: BindSnapshots003 -@tc.desc: RdbGeneralStore BindSnapshots not nullptr test -@tc.type: FUNC +* @tc.name: BindSnapshots003 +* @tc.desc: RdbGeneralStore BindSnapshots not nullptr test +* @tc.type: FUNC */ HWTEST_F(RdbGeneralStoreTest, BindSnapshots003, TestSize.Level1) { diff --git a/services/distributeddataservice/service/test/rdb_service_impl_test.cpp b/services/distributeddataservice/service/test/rdb_service_impl_test.cpp index f144db0ff..39c293081 100644 --- a/services/distributeddataservice/service/test/rdb_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/rdb_service_impl_test.cpp @@ -15,6 +15,7 @@ #include +#include "rdb_service_impl.h" #include "account/account_delegate.h" #include "bootstrap.h" #include "checker_mock.h" @@ -104,7 +105,6 @@ void RdbServiceImplTest::InitMapping(StoreMetaMapping &metaMapping) void RdbServiceImplTest::InitMetaDataManager() { - MetaDataManager::GetInstance().Initialize(dbStoreMock_, nullptr, ""); MetaDataManager::GetInstance().SetSyncer([](const auto &, auto) { DeviceMatrix::GetInstance().OnChanged(DeviceMatrix::META_STORE_MASK); }); @@ -120,7 +120,11 @@ void RdbServiceImplTest::SetUpTestCase() EXPECT_CALL(*deviceManagerAdapterMock, GetUuidByNetworkId(_)).WillRepeatedly(Return(deviceInfo.uuid)); EXPECT_CALL(*deviceManagerAdapterMock, CalcClientUuid(_, _)).WillRepeatedly(Return(deviceInfo.uuid)); EXPECT_CALL(*deviceManagerAdapterMock, ToUUID(deviceInfo.uuid)).WillRepeatedly(Return(deviceInfo.uuid)); + size_t max = 12; + size_t min = 5; + auto dmExecutor = std::make_shared(max, min); + DeviceManagerAdapter::GetInstance().Init(dmExecutor); InitMetaData(); Bootstrap::GetInstance().LoadCheckers(); CryptoManager::GetInstance().GenerateRootKey(); @@ -642,7 +646,6 @@ HWTEST_F(RdbServiceImplTest, DoAutoSync001, TestSize.Level0) std::vector devices = {"device1"}; DistributedData::Database dataBase; std::vector tables = {"table1"}; - auto result = service.DoAutoSync(devices, dataBase, tables); EXPECT_EQ(result, RDB_ERROR); } @@ -838,7 +841,7 @@ HWTEST_F(RdbServiceImplTest, AfterOpen004, TestSize.Level0) param.bundleName_ = metaData_.bundleName; param.storeName_ = metaData_.storeId; int32_t result = service.AfterOpen(param); - + EXPECT_EQ(result, RDB_OK); EXPECT_EQ(MetaDataManager::GetInstance().DelMeta(metaData_.GetKeyWithoutPath(), false), true); } @@ -1311,10 +1314,9 @@ HWTEST_F(RdbServiceImplTest, Sync004, TestSize.Level0) EXPECT_EQ(result, RDB_OK); } - /** * @tc.name: QuerySharingResource001 - * @tc.desc: Test QuerySharingResource when CheckParam not pass. + * @tc.desc: Test QuerySharingResource when CheckAccess not pass. * @tc.type: FUNC * @tc.require: * @tc.author: zd @@ -1325,10 +1327,11 @@ HWTEST_F(RdbServiceImplTest, QuerySharingResource001, TestSize.Level0) RdbSyncerParam param; PredicatesMemo predicates; std::vector columns; + auto result = service.QuerySharingResource(param, predicates, columns); EXPECT_EQ(result.first, RDB_ERROR); } - + /** * @tc.name: BeforeOpen001 * @tc.desc: Test BeforeOpen when CheckParam not pass. @@ -1398,6 +1401,26 @@ HWTEST_F(RdbServiceImplTest, BeforeOpen004, TestSize.Level0) EXPECT_EQ(MetaDataManager::GetInstance().DelMeta(metaData_.GetKey(), true), true); } +/** + * @tc.name: BeforeOpen005 + * @tc.desc: Test BeforeOpen when checkacess pass and CheckParam pass. + * @tc.type: FUNC + * @tc.require: + * @tc.author: my + */ +HWTEST_F(RdbServiceImplTest, BeforeOpen005, TestSize.Level0) +{ + EXPECT_EQ(MetaDataManager::GetInstance().SaveMeta(metaData_.GetKey(), metaData_, true), true); + RdbServiceImpl service; + RdbSyncerParam param; + param.bundleName_ = TEST_BUNDLE; + param.storeName_ = TEST_STORE; + param.subUser_ = 100; + int32_t result = service.BeforeOpen(param); + EXPECT_EQ(result, RDB_NO_META); + EXPECT_EQ(MetaDataManager::GetInstance().DelMeta(metaData_.GetKey(), true), true); +} + /** * @tc.name: Subscribe001 * @tc.desc: Test Subscribe when option mode invalid. -- Gitee