diff --git a/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h b/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h index 69f0a45e6611b5c8d16bff33fba4337e3e121c7d..cb21e60accfbbe091514de7676be27c2880a94ab 100644 --- a/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h +++ b/interfaces/inner_api/native/cloud_file_kit_inner/data_sync_const.h @@ -57,6 +57,7 @@ struct LocalInfo { int64_t rowId; int32_t thm_flag; int32_t lcd_flag; + int32_t dirtyType; }; struct BundleNameUserInfo { diff --git a/services/clouddisk_database/include/clouddisk_rdbstore.h b/services/clouddisk_database/include/clouddisk_rdbstore.h index 189996508d2b061767bdbd081f8558fe849e5c92..dec9247ad212f811be042e420182a6d09d5a5b11 100644 --- a/services/clouddisk_database/include/clouddisk_rdbstore.h +++ b/services/clouddisk_database/include/clouddisk_rdbstore.h @@ -73,10 +73,10 @@ public: int32_t GetRowId(const std::string &cloudId, int64_t &rowId); int32_t GetParentCloudId(const std::string &cloudId, std::string &parentCloudId); int32_t ExtAttributeSetXattr(const std::string &cloudId, const std::string &value, const std::string &key); - int32_t GetExtAttr(const std::string &cloudId, std::string &value, int32_t &position); + int32_t GetExtAttr(const std::string &cloudId, std::string &value, int32_t &position, int32_t &dirtyType); int32_t GetExtAttrValue(const std::string &cloudId, const std::string &key, std::string &value); int32_t GetRecycleInfo(std::shared_ptr transaction, - const std::string &cloudId, int64_t &rowId, int32_t &position, std::string &attr); + const std::string &cloudId, int64_t &rowId, int32_t &position, std::string &attr, int32_t &dirtyType); int32_t GetSourcePath(const std::string &attr, const std::string &parentCloudId, std::string &sourcePath); int32_t SourcePathSetValue(const std::string &cloudId, const std::string &attr, NativeRdb::ValuesBucket &setXattr); int32_t HandleRecycleXattr(const std::string &name, const std::string &parentCloudId, const std::string &cloudId); @@ -96,6 +96,8 @@ public: const int userId, std::string destPath); int32_t CreateDentryFile(MetaBase metaBase, std::string destParentCloudId); int32_t GetSrcCloudId(const std::string &cloudId, std::string &srcCloudId); + int32_t HandleRenameValue(NativeRdb::ValuesBucket &rename, int32_t position, uint8_t noNeedUpload, + const CacheNode &oldNode, const CacheNode &newNode); int32_t UpdateTHMStatus(std::shared_ptr metaFile, MetaBase &metabase, int32_t status); void DatabaseRestore(); diff --git a/services/clouddisk_database/src/clouddisk_rdbstore.cpp b/services/clouddisk_database/src/clouddisk_rdbstore.cpp index 0698210eabb58c8185fae5c0f44d83bed5a51a91..6886bf9794c946a8fd3014bb5304acd179c47761 100644 --- a/services/clouddisk_database/src/clouddisk_rdbstore.cpp +++ b/services/clouddisk_database/src/clouddisk_rdbstore.cpp @@ -797,10 +797,12 @@ int32_t CloudDiskRdbStore::GetRowId(const std::string &cloudId, int64_t &rowId) return E_OK; } -static int32_t RecycleSetValue(TrashOptType val, ValuesBucket &setXAttr, int32_t position) +static int32_t RecycleSetValue(TrashOptType val, ValuesBucket &setXAttr, int32_t position, int32_t dirtyType) { if (position != LOCAL) { - setXAttr.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + if (dirtyType != static_cast(DirtyType::TYPE_FDIRTY)) { + setXAttr.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + } } else { setXAttr.PutInt(FileColumn::OPERATE_TYPE, static_cast(OperationType::NEW)); } @@ -999,13 +1001,14 @@ int32_t CloudDiskRdbStore::HandleRestoreXattr(const string &name, const string & int64_t rowId = 0; int32_t position = -1; string attr; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); TransactionOperations rdbTransaction(rdbStore_); auto [ret, transaction] = rdbTransaction.Start(); if (ret != E_OK) { LOGE("rdbstore begin transaction failed, ret = %{public}d", ret); return ret; } - ret = GetRecycleInfo(transaction, cloudId, rowId, position, attr); + ret = GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); if (ret != E_OK) { LOGE("get recycle fields fail, ret %{public}d", ret); return E_RDB; @@ -1023,7 +1026,7 @@ int32_t CloudDiskRdbStore::HandleRestoreXattr(const string &name, const string & ValuesBucket setXAttr; setXAttr.PutString(FileColumn::PARENT_CLOUD_ID, realParentCloudId); setXAttr.PutString(FileColumn::FILE_NAME, newName); - RETURN_ON_ERR(RecycleSetValue(TrashOptType::RESTORE, setXAttr, position)); + RETURN_ON_ERR(RecycleSetValue(TrashOptType::RESTORE, setXAttr, position, dirtyType)); struct RestoreInfo restoreInfo = {name, realParentCloudId, newName, rowId}; ret = RestoreUpdateRdb(cloudId, restoreInfo, setXAttr); if (ret != E_OK) { @@ -1040,20 +1043,21 @@ int32_t CloudDiskRdbStore::HandleRecycleXattr(const string &name, const string & int64_t rowId = 0; int32_t position = -1; string attr; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); TransactionOperations rdbTransaction(rdbStore_); auto [ret, transaction] = rdbTransaction.Start(); if (ret != E_OK) { LOGE("rdbstore begin transaction failed, ret = %{public}d", ret); return ret; } - ret = GetRecycleInfo(transaction, cloudId, rowId, position, attr); + ret = GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); if (ret != E_OK) { LOGE("get rowId and position fail, ret %{public}d", ret); return E_RDB; } ValuesBucket setXAttr; SourcePathSetValue(cloudId, attr, setXAttr); - ret = RecycleSetValue(TrashOptType::RECYCLE, setXAttr, position); + ret = RecycleSetValue(TrashOptType::RECYCLE, setXAttr, position, dirtyType); if (ret != E_OK) { return ret; } @@ -1077,14 +1081,15 @@ int32_t CloudDiskRdbStore::HandleRecycleXattr(const string &name, const string & } int32_t CloudDiskRdbStore::GetRecycleInfo(shared_ptr transaction, const std::string &cloudId, - int64_t &rowId, int32_t &position, string &attr) + int64_t &rowId, int32_t &position, string &attr, int32_t &dirtyType) { RDBPTR_IS_NULLPTR(rdbStore_); CLOUDID_IS_NULL(cloudId); AbsRdbPredicates getRowIdAndPositionPredicates = AbsRdbPredicates(FileColumn::FILES_TABLE); getRowIdAndPositionPredicates.EqualTo(FileColumn::CLOUD_ID, cloudId); auto resultSet = transaction->QueryByStep(getRowIdAndPositionPredicates, - {FileColumn::ROW_ID, FileColumn::POSITION, FileColumn::ATTRIBUTE}); + {FileColumn::ROW_ID, FileColumn::POSITION, FileColumn::ATTRIBUTE, + FileColumn::DIRTY_TYPE}); if (resultSet == nullptr) { LOGE("get nullptr result set"); return E_RDB; @@ -1108,6 +1113,11 @@ int32_t CloudDiskRdbStore::GetRecycleInfo(shared_ptr transaction, c LOGE("get file attribute failed"); return ret; } + ret = CloudDiskRdbUtils::GetInt(FileColumn::DIRTY_TYPE, dirtyType, resultSet); + if (ret != E_OK) { + LOGE("get dirtyType failed"); + return ret; + } return E_OK; } @@ -1268,7 +1278,8 @@ int32_t CloudDiskRdbStore::GetExtAttrValue(const std::string &cloudId, const std std::string res; int32_t pos = 0; - int32_t ret = GetExtAttr(cloudId, res, pos); + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + int32_t ret = GetExtAttr(cloudId, res, pos, dirtyType); if (ret != E_OK || res.empty()) { LOGE("get ext attr value res is empty"); return E_RDB; @@ -1290,7 +1301,8 @@ int32_t CloudDiskRdbStore::GetExtAttrValue(const std::string &cloudId, const std return E_OK; } -int32_t CloudDiskRdbStore::GetExtAttr(const std::string &cloudId, std::string &value, int32_t &position) +int32_t CloudDiskRdbStore::GetExtAttr(const std::string &cloudId, std::string &value, int32_t &position, + int32_t &dirtyType) { RDBPTR_IS_NULLPTR(rdbStore_); if (cloudId.empty() || cloudId == ROOT_CLOUD_ID) { @@ -1320,7 +1332,11 @@ int32_t CloudDiskRdbStore::GetExtAttr(const std::string &cloudId, std::string &v LOGE("get location value failed"); return ret; } - + ret = CloudDiskRdbUtils::GetInt(FileColumn::DIRTY_TYPE, dirtyType, resultSet); + if (ret != E_OK) { + LOGE("get dirtyType value failed"); + return ret; + } return E_OK; } @@ -1353,7 +1369,7 @@ int32_t CloudDiskRdbStore::GetXAttr(const std::string &cloudId, const std::strin } static int32_t ExtAttributeSetValue(const std::string &key, const std::string &value, - ValuesBucket &setXAttr, std::string &xattrList, int32_t pos) + ValuesBucket &setXAttr, std::string &xattrList, int32_t pos, int32_t dirtyType) { auto jsonObj = nlohmann::json::parse(xattrList, nullptr, false); if (jsonObj.is_discarded() || (!jsonObj.is_object())) { @@ -1378,7 +1394,9 @@ static int32_t ExtAttributeSetValue(const std::string &key, const std::string &v setXAttr.PutString(FileColumn::ATTRIBUTE, jsonValue); if (pos != LOCAL) { - setXAttr.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + if (dirtyType != static_cast(DirtyType::TYPE_FDIRTY)) { + setXAttr.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + } setXAttr.PutLong(FileColumn::OPERATE_TYPE, static_cast(OperationType::UNKNOWN_TYPE)); } setXAttr.PutLong(FileColumn::META_TIME_EDITED, UTCTimeMilliSeconds()); @@ -1399,8 +1417,9 @@ int32_t CloudDiskRdbStore::ExtAttributeSetXattr(const std::string &cloudId, cons } std::string xattrList; int32_t pos = 0; - RETURN_ON_ERR(GetExtAttr(cloudId, xattrList, pos)); - RETURN_ON_ERR(ExtAttributeSetValue(key, value, setAttr, xattrList, pos)); + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + RETURN_ON_ERR(GetExtAttr(cloudId, xattrList, pos, dirtyType)); + RETURN_ON_ERR(ExtAttributeSetValue(key, value, setAttr, xattrList, pos, dirtyType)); NativeRdb::AbsRdbPredicates predicates = NativeRdb::AbsRdbPredicates(FileColumn::FILES_TABLE); predicates.EqualTo(FileColumn::CLOUD_ID, cloudId); std::tie(ret, changedRows) = transaction->Update(setAttr, predicates); @@ -1441,57 +1460,69 @@ int32_t CloudDiskRdbStore::SetXAttr(const std::string &cloudId, const std::strin return ret; } -static void FileRename(ValuesBucket &values, const int32_t &position, const std::string &newFileName) +static void FileRename(ValuesBucket &values, const int32_t &position, const std::string &newFileName, + const int32_t dirtyType) { values.PutString(FileColumn::FILE_NAME, newFileName); values.PutInt(FileColumn::FILE_STATUS, FileStatus::TO_BE_UPLOADED); FillFileType(newFileName, values); if (position != LOCAL) { - values.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + if (dirtyType != static_cast(DirtyType::TYPE_FDIRTY)) { + values.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + } values.PutLong(FileColumn::OPERATE_TYPE, static_cast(OperationType::RENAME)); } } -static void FileMove(ValuesBucket &values, const int32_t &position, const std::string &newParentCloudId) +static void FileMove(ValuesBucket &values, const int32_t &position, const std::string &newParentCloudId, + const int32_t dirtyType) { values.PutString(FileColumn::PARENT_CLOUD_ID, newParentCloudId); values.PutInt(FileColumn::FILE_STATUS, FileStatus::TO_BE_UPLOADED); if (position != LOCAL) { - values.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + if (dirtyType != static_cast(DirtyType::TYPE_FDIRTY)) { + values.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + } values.PutLong(FileColumn::OPERATE_TYPE, static_cast(OperationType::MOVE)); } } static void FileMoveAndRename(ValuesBucket &values, const int32_t &position, const std::string &newParentCloudId, - const std::string &newFileName) + const std::string &newFileName, const int32_t dirtyType) { values.PutString(FileColumn::PARENT_CLOUD_ID, newParentCloudId); values.PutString(FileColumn::FILE_NAME, newFileName); values.PutInt(FileColumn::FILE_STATUS, FileStatus::TO_BE_UPLOADED); FillFileType(newFileName, values); if (position != LOCAL) { - values.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + if (dirtyType != static_cast(DirtyType::TYPE_FDIRTY)) { + values.PutInt(FileColumn::DIRTY_TYPE, static_cast(DirtyType::TYPE_MDIRTY)); + } values.PutLong(FileColumn::OPERATE_TYPE, static_cast(OperationType::MOVE)); } } -static void HandleRenameValue(ValuesBucket &rename, int32_t position, const CacheNode &oldNode, - const CacheNode &newNode) +int32_t CloudDiskRdbStore::HandleRenameValue(ValuesBucket &rename, int32_t position, uint8_t noNeedUpload, + const CacheNode &oldNode, const CacheNode &newNode) { string oldParentCloudId = oldNode.parentCloudId; string oldFileName = oldNode.fileName; string newParentCloudId = newNode.parentCloudId; string newFileName = newNode.fileName; rename.PutLong(FileColumn::META_TIME_EDITED, UTCTimeMilliSeconds()); + rename.PutInt(FileColumn::NO_NEED_UPLOAD, noNeedUpload); + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + RETURN_ON_ERR(GetDirtyType(oldNode.cloudId, dirtyType)); if (oldFileName != newFileName && oldParentCloudId == newParentCloudId) { - FileRename(rename, position, newFileName); + FileRename(rename, position, newFileName, dirtyType); } if (oldFileName == newFileName && oldParentCloudId != newParentCloudId) { - FileMove(rename, position, newParentCloudId); + FileMove(rename, position, newParentCloudId, dirtyType); } if (oldFileName != newFileName && oldParentCloudId != newParentCloudId) { - FileMoveAndRename(rename, position, newParentCloudId, newFileName); + FileMoveAndRename(rename, position, newParentCloudId, newFileName, dirtyType); } + return E_OK; } int32_t CloudDiskRdbStore::Rename(const std::string &oldParentCloudId, const std::string &oldFileName, @@ -1520,7 +1551,7 @@ int32_t CloudDiskRdbStore::Rename(const std::string &oldParentCloudId, const std ValuesBucket rename; CacheNode newNode = {.parentCloudId = newParentCloudId, .fileName = newFileName}; CacheNode oldNode = {.parentCloudId = oldParentCloudId, .fileName = oldFileName}; - HandleRenameValue(rename, metaBase.position, oldNode, newNode); + RETURN_ON_ERR(HandleRenameValue(rename, metaBase.position, metaBase.noUpload, oldNode, newNode)); vector bindArgs; bindArgs.emplace_back(metaBase.cloudId); auto newMetaFile = MetaFileMgr::GetInstance().GetCloudDiskMetaFile(userId_, bundleName_, newParentCloudId); diff --git a/services/clouddisk_database/src/file_column.cpp b/services/clouddisk_database/src/file_column.cpp index 0370d6a1d4230699c70de516573d504bed073d52..68b0037684ae2268b8119e004508920aad45dd20 100644 --- a/services/clouddisk_database/src/file_column.cpp +++ b/services/clouddisk_database/src/file_column.cpp @@ -134,7 +134,7 @@ const std::string FileColumn::ADD_THM_SIZE = "ALTER Table " + FILES_TABLE + const std::string FileColumn::ADD_LCD_SIZE = "ALTER Table " + FILES_TABLE + " ADD COLUMN " + LCD_SIZE + " INT DEFAULT 0"; - const std::string FileColumn::ADD_SOURCE_CLOUD_ID = "ALTER Table " + FILES_TABLE + +const std::string FileColumn::ADD_SOURCE_CLOUD_ID = "ALTER Table " + FILES_TABLE + " ADD COLUMN " + SOURCE_CLOUD_ID + " TEXT"; const std::vector FileColumn::FILE_SYSTEM_QUERY_COLUMNS = { @@ -229,6 +229,7 @@ const std::vector FileColumn::DISK_ON_UPLOAD_COLUMNS = { ROW_ID, THM_FLAG, LCD_FLAG, + DIRTY_TYPE, }; const std::vector FileColumn::DISK_CLOUD_FOR_THM_INSERT = { @@ -244,7 +245,8 @@ const std::vector FileColumn::DISK_CLOUD_FOR_THM_INSERT = { const std::vector FileColumn::EXT_ATTR_QUERY_COLUMNS = { ATTRIBUTE, - POSITION + POSITION, + DIRTY_TYPE, }; } // namespace CloudDisk } // namespace FileManagement diff --git a/test/unittests/cloud_disk/mock/clouddisk_rdbstore_mock.cpp b/test/unittests/cloud_disk/mock/clouddisk_rdbstore_mock.cpp index b360365a77fe874bb964f2cfdb3b0b1afe65ae92..ed3d20179ac29467decb2b66ebdd2358e4bc67cc 100644 --- a/test/unittests/cloud_disk/mock/clouddisk_rdbstore_mock.cpp +++ b/test/unittests/cloud_disk/mock/clouddisk_rdbstore_mock.cpp @@ -153,7 +153,8 @@ int32_t CloudDiskRdbStore::GetExtAttrValue(const std::string &cloudId, const std return E_OK; } -int32_t CloudDiskRdbStore::GetExtAttr(const std::string &cloudId, std::string &value, int32_t &position) +int32_t CloudDiskRdbStore::GetExtAttr(const std::string &cloudId, std::string &value, int32_t &position, + int32_t &dirtyType) { return E_OK; } diff --git a/test/unittests/clouddisk_database/BUILD.gn b/test/unittests/clouddisk_database/BUILD.gn index 74bad1e926041bc3065f4c10776e3fae43c592fe..4b3123c84ff238c8d153184867fa0ee022ec99aa 100644 --- a/test/unittests/clouddisk_database/BUILD.gn +++ b/test/unittests/clouddisk_database/BUILD.gn @@ -201,6 +201,122 @@ ohos_unittest("clouddisk_rdbstore_test") { use_exceptions = true } +ohos_unittest("clouddisk_rdbstore_static_test") { + branch_protector_ret = "pac_ret" + public_configs = + [ "${services_path}/cloudsyncservice:cloud_sync_service_public_config" ] + sanitize = { + integer_overflow = true + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${distributedfile_path}/cfi_blocklist.txt" + } + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_callback_client.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_callback_stub.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_uri_manager.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_optimize_callback_client.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_optimize_callback_stub.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_callback_client.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_callback_stub.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/service_proxy.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_manager_impl_lite.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/src/cloud_sync_manager_lite.cpp", + "${distributedfile_path}/test/unittests/clouddisk_database/mock/clouddisk_notify_utils_mock.cpp", + "${distributedfile_path}/test/unittests/clouddisk_database/mock/clouddisk_rdb_transaction_mock.cpp", + "${distributedfile_path}/test/unittests/clouddisk_database/mock/meta_file_clouddisk_mock.cpp", + "${distributedfile_path}/test/unittests/clouddisk_database/mock/rdb_mock.cpp", + "${distributedfile_path}/test/unittests/clouddisk_database/mock/transaction_mock.cpp", + "${distributedfile_path}/test/unittests/cloudsync_sa/mock/cloud_file_utils_mock.cpp", + "${distributedfile_path}/test/unittests/cloudsync_sa/mock/parameters.cpp", + "clouddisk_rdbstore_static_test.cpp", + ] + + clouddisk_database = [ + "${services_path}/clouddisk_database/src/clouddisk_rdb_utils.cpp", + "${services_path}/clouddisk_database/src/file_column.cpp", + "${services_path}/clouddisk_database/src/clouddisk_sync_helper.cpp", + "${services_path}/clouddisk_database/src/clouddisk_notify.cpp", + ] + + sources += clouddisk_database + include_dirs = [ + "${services_path}/clouddisk_database/include", + "${distributedfile_path}/adapter/cloud_adapter_example/include", + "${services_path}/cloudsyncservice/include", + "${services_path}/cloudfiledaemon/include", + "${distributedfile_path}/interfaces/inner_api/native/cloudsync_kit_inner", + "${distributedfile_path}/adapter/cloud_adapter_example/include", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/include", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/include", + "${utils_path}/log/include", + "${distributedfile_path}/test/unittests/clouddisk_database/include", + "${distributedfile_path}/test/unittests/clouddisk_database/mock", + "${services_path}/cloudfiledaemon/include/cloud_disk", + "${services_path}/clouddisk_database/src", + ] + + deps = [ + "${innerkits_native_path}/cloud_file_kit_inner:cloudfile_kit", + "${services_path}/cloudsyncservice:cloud_sync_service_proxy", + "${utils_path}:libdistributedfileutils", + "${utils_path}:libdistributedfileutils_lite", + ] + + cflags = [ "--coverage" ] + + ldflags = [ "--coverage" ] + + cflags_cc = [ "--coverage" ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:dataobs_manager", + "app_file_service:sandbox_helper_native", + "c_utils:utils", + "e2fsprogs:libext2_blkid", + "e2fsprogs:libext2_uuid", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_single", + "libfuse:libfuse", + "netmanager_base:net_conn_manager_if", + "os_account:os_account_innerkits", + "preferences:native_preferences", + "relational_store:native_rdb", + "samgr:samgr_proxy", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD004310", + "LOG_TAG=\"CLOUDDISK_DATABASE_TEST\"", + ] + + if (cloudsync_service_hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (support_thermal_manager) { + external_deps += [ "bundle_framework:appexecfwk_base" ] + external_deps += [ "thermal_manager:thermalmgr_listener" ] + external_deps += [ "thermal_manager:thermalsrv_client" ] + defines += [ "support_thermal_manager" ] + } + + use_exceptions = true +} + ohos_unittest("clouddisk_notify_test") { branch_protector_ret = "pac_ret" public_configs = diff --git a/test/unittests/clouddisk_database/clouddisk_rdbstore_static_test.cpp b/test/unittests/clouddisk_database/clouddisk_rdbstore_static_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0eb8cbee685e61732d1125466811154672277b2 --- /dev/null +++ b/test/unittests/clouddisk_database/clouddisk_rdbstore_static_test.cpp @@ -0,0 +1,271 @@ +/* +* Copyright (C) 2024-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 +#include +#include + +#include "cloud_file_utils.h" +#include "cloud_status.h" +#include "clouddisk_notify_utils_mock.h" +#include "clouddisk_rdb_utils.h" +#include "clouddisk_rdbstore.cpp" +#include "dfs_error.h" +#include "rdb_assistant.h" +#include "result_set_mock.h" +#include "transaction_mock.cpp" + +namespace OHOS::FileManagement::CloudDisk::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; +using namespace NativeRdb; +using namespace OHOS::FileManagement::CloudDisk; + +static const string BUNDLE_NAME = "com.ohos.photos"; +static const int32_t USER_ID = 100; +class CloudDiskRdbStoreStaticTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr clouddiskrdbStore_ = nullptr; + static inline shared_ptr insMock = nullptr; +}; + +void CloudDiskRdbStoreStaticTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + insMock = make_shared(); + Assistant::ins = insMock; + clouddiskrdbStore_ = make_shared(BUNDLE_NAME, USER_ID); +} + +void CloudDiskRdbStoreStaticTest::TearDownTestCase(void) +{ + Assistant::ins = nullptr; + insMock = nullptr; + clouddiskrdbStore_ = nullptr; + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void CloudDiskRdbStoreStaticTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void CloudDiskRdbStoreStaticTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: FileRenameTest001 + * @tc.desc: Verify the FileRename + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileRenameTest001, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = CLOUD; + const std::string newFileName = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + FileRename(values, position, newFileName, dirtyType); + EXPECT_EQ(newFileName, "test"); +} + +/** + * @tc.name: FileRenameTest002 + * @tc.desc: Verify the FileRename + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileRenameTest002, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = LOCAL; + const std::string newFileName = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + FileRename(values, position, newFileName, dirtyType); + EXPECT_EQ(newFileName, "test"); +} + +/** + * @tc.name: FileRenameTest003 + * @tc.desc: Verify the FileRename + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileRenameTest003, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = CLOUD; + const std::string newFileName = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + + FileRename(values, position, newFileName, dirtyType); + EXPECT_EQ(position, CLOUD); +} + +/** + * @tc.name: RecycleSetValue + * @tc.desc: Verify the RecycleSetValue + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, RecycleSetValueTest1, TestSize.Level1) +{ + ValuesBucket setXAttr; + int32_t position = CLOUD; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + RecycleSetValue(TrashOptType::RECYCLE, setXAttr, position, dirtyType); + EXPECT_EQ(position, CLOUD); +} + +/** + * @tc.name: FileMoveTest001 + * @tc.desc: Verify the FileMove + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileMoveTest001, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = CLOUD; + const std::string newParentCloudId = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + FileMove(values, position, newParentCloudId, dirtyType); + EXPECT_EQ(newParentCloudId, "test"); +} + +/** + * @tc.name: FileMoveTest002 + * @tc.desc: Verify the FileMove + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileMoveTest002, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = LOCAL; + const std::string newParentCloudId = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + FileMove(values, position, newParentCloudId, dirtyType); + EXPECT_EQ(newParentCloudId, "test"); +} + +/** + * @tc.name: FileMoveTest003 + * @tc.desc: Verify the FileMove + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileMoveTest003, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = CLOUD; + const std::string newParentCloudId = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + + FileMove(values, position, newParentCloudId, dirtyType); + EXPECT_EQ(newParentCloudId, "test"); +} + +/** + * @tc.name: FileMoveAndRenameTest001 + * @tc.desc: Verify the FileMoveAndRename + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileMoveAndRenameTest001, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = CLOUD; + const std::string newParentCloudId = "test"; + const std::string newFileName = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + FileMoveAndRename(values, position, newParentCloudId, newFileName, dirtyType); + EXPECT_EQ(newFileName, "test"); +} + +/** + * @tc.name: FileMoveAndRenameTest002 + * @tc.desc: Verify the FileMoveAndRename + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileMoveAndRenameTest002, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = LOCAL; + const std::string newParentCloudId = "test"; + const std::string newFileName = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + FileMoveAndRename(values, position, newParentCloudId, newFileName, dirtyType); + EXPECT_EQ(newFileName, "test"); +} + +/** + * @tc.name: FileMoveAndRenameTest003 + * @tc.desc: Verify the FileMoveAndRename + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, FileMoveAndRenameTest003, TestSize.Level1) +{ + ValuesBucket values; + const int32_t position = CLOUD; + const std::string newParentCloudId = "test"; + const std::string newFileName = "test"; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + + FileMoveAndRename(values, position, newParentCloudId, newFileName, dirtyType); + EXPECT_EQ(newFileName, "test"); +} + +/** + * @tc.name: ExtAttributeSetValueTest001 + * @tc.desc: Verify the ExtAttributeSetValue + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, ExtAttributeSetValueTest1, TestSize.Level1) +{ + const std::string key = "testKey"; + std::string value = "testValue"; + ValuesBucket setAttr; + const int32_t pos = CLOUD; + std::string xattrList = "{}"; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + + int32_t result = ExtAttributeSetValue(key, value, setAttr, xattrList, pos, dirtyType); + EXPECT_EQ(result, E_OK); +} + +/** + * @tc.name: ExtAttributeSetValueTest002 + * @tc.desc: Verify the ExtAttributeSetValue + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreStaticTest, ExtAttributeSetValueTest002, TestSize.Level1) +{ + const std::string key = "testKey"; + std::string value = "testValue"; + ValuesBucket setAttr; + const int32_t pos = CLOUD; + std::string xattrList = "{}"; + int32_t dirtyType = static_cast(DirtyType::TYPE_FDIRTY); + + int32_t result = ExtAttributeSetValue(key, value, setAttr, xattrList, pos, dirtyType); + EXPECT_EQ(result, E_OK); +} +} // namespace OHOS::FileManagement::CloudDisk::Test \ No newline at end of file diff --git a/test/unittests/clouddisk_database/clouddisk_rdbstore_test.cpp b/test/unittests/clouddisk_database/clouddisk_rdbstore_test.cpp index 4fa7246c00bffd388ce36fe44903da6d1f56740c..4bac244e4797d41d804d14a33e4d1fe40239c089 100644 --- a/test/unittests/clouddisk_database/clouddisk_rdbstore_test.cpp +++ b/test/unittests/clouddisk_database/clouddisk_rdbstore_test.cpp @@ -300,7 +300,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetAttrTest4, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetRow(_)).WillRepeatedly(Return(E_OK)); - + int32_t ret = clouddiskrdbStore_->GetAttr(cloudId, info); EXPECT_EQ(ret, E_OK); } @@ -352,7 +352,7 @@ HWTEST_F(CloudDiskRdbStoreTest, SetAttrTest3, TestSize.Level1) const unsigned long long size = 0; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + auto transaction = make_shared(); EXPECT_CALL(*rdb, CreateTransaction(_)).WillOnce(Return(std::make_pair(E_OK, transaction))); EXPECT_CALL(*transaction, Update(_, _, _)).WillOnce(Return(std::make_pair(E_RDB, 0))); @@ -374,7 +374,7 @@ HWTEST_F(CloudDiskRdbStoreTest, SetAttrTest4, TestSize.Level1) const unsigned long long size = 0; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + auto transaction = make_shared(); EXPECT_CALL(*rdb, CreateTransaction(_)).WillOnce(Return(std::make_pair(E_OK, transaction))); EXPECT_CALL(*transaction, Update(_, _, _)).WillOnce(Return(std::make_pair(E_OK, 0))); @@ -571,7 +571,7 @@ HWTEST_F(CloudDiskRdbStoreTest, CreateTest8, TestSize.Level1) clouddiskrdbStore_->userId_ = 1; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + auto transaction = make_shared(); EXPECT_CALL(*rdb, CreateTransaction(_)).WillOnce(Return(std::make_pair(E_OK, transaction))); EXPECT_CALL(*transaction, Insert(_, _, _)).WillOnce(Return(std::make_pair(E_RDB, 0))); @@ -644,7 +644,7 @@ HWTEST_F(CloudDiskRdbStoreTest, MkDirTest4, TestSize.Level1) bool noNeedUpload = false; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + auto transaction = make_shared(); EXPECT_CALL(*rdb, CreateTransaction(_)).WillOnce(Return(std::make_pair(E_OK, transaction))); EXPECT_CALL(*transaction, Insert(_, _, _)).WillOnce(Return(std::make_pair(E_RDB, 0))); @@ -744,7 +744,7 @@ HWTEST_F(CloudDiskRdbStoreTest, WriteTest3, TestSize.Level1) auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; clouddiskrdbStore_->userId_ = 0; - + int32_t ret = clouddiskrdbStore_->Write(fileName, parentCloudId, cloudId); EXPECT_EQ(ret, E_PATH); } @@ -1833,7 +1833,7 @@ HWTEST_F(CloudDiskRdbStoreTest, HandleRecycleXattrTest4, TestSize.Level1) } /** - * @tc.name: GetRecycleInfo + * @tc.name: GetRecycleInfoTest001 * @tc.desc: Verify the CloudDiskRdbStore::GetRecycleInfo function * @tc.type: FUNC */ @@ -1844,6 +1844,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest1, TestSize.Level1) int32_t position; std::string attr; bool preCount = true; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; auto transaction = make_shared(); @@ -1851,12 +1852,12 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest1, TestSize.Level1) EXPECT_CALL(*transaction, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(nullptr))); - int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr); + int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); EXPECT_EQ(ret, E_RDB); } /** - * @tc.name: GetRecycleInfo + * @tc.name: GetRecycleInfoTest002 * @tc.desc: Verify the CloudDiskRdbStore::GetRecycleInfo function * @tc.type: FUNC */ @@ -1867,6 +1868,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest2, TestSize.Level1) int32_t position; std::string attr; bool preCount = true; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; auto transaction = make_shared(); @@ -1875,12 +1877,12 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest2, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_RDB)); - int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr); + int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); EXPECT_EQ(ret, E_RDB); } /** - * @tc.name: GetRecycleInfo + * @tc.name: GetRecycleInfoTest003 * @tc.desc: Verify the CloudDiskRdbStore::GetRecycleInfo function * @tc.type: FUNC */ @@ -1891,6 +1893,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest3, TestSize.Level1) int32_t position; std::string attr; bool preCount = true; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; auto transaction = make_shared(); @@ -1900,12 +1903,12 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest3, TestSize.Level1) EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetLong(_, _)).WillRepeatedly(Return(E_RDB)); - int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr); + int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); EXPECT_EQ(ret, E_RDB); } /** - * @tc.name: GetRecycleInfo + * @tc.name: GetRecycleInfoTest004 * @tc.desc: Verify the CloudDiskRdbStore::GetRecycleInfo function * @tc.type: FUNC */ @@ -1915,6 +1918,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest4, TestSize.Level1) int64_t rowId; int32_t position; std::string attr; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); bool preCount = true; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; @@ -1926,12 +1930,12 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest4, TestSize.Level1) EXPECT_CALL(*rset, GetLong(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_RDB)); - int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr); + int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); EXPECT_EQ(ret, E_RDB); } /** - * @tc.name: GetRecycleInfo + * @tc.name: GetRecycleInfoTest005 * @tc.desc: Verify the CloudDiskRdbStore::GetRecycleInfo function * @tc.type: FUNC */ @@ -1942,6 +1946,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest5, TestSize.Level1) int32_t position; std::string attr; bool preCount = true; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; auto transaction = make_shared(); @@ -1953,12 +1958,12 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest5, TestSize.Level1) EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_RDB)); - int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr); + int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); EXPECT_EQ(ret, E_RDB); } /** - * @tc.name: GetRecycleInfo + * @tc.name: GetRecycleInfoTest006 * @tc.desc: Verify the CloudDiskRdbStore::GetRecycleInfo function * @tc.type: FUNC */ @@ -1969,6 +1974,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest6, TestSize.Level1) int32_t position; std::string attr; bool preCount = true; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; auto transaction = make_shared(); @@ -1980,10 +1986,39 @@ HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest6, TestSize.Level1) EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_OK)); - int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr); + int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); EXPECT_EQ(ret, E_OK); } +/** + * @tc.name: GetRecycleInfoTest007 + * @tc.desc: Verify the CloudDiskRdbStore::GetRecycleInfo function + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreTest, GetRecycleInfoTest7, TestSize.Level1) +{ + const std::string cloudId = "100"; + int64_t rowId; + int32_t position; + std::string attr; + bool preCount = true; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + auto rdb = make_shared(); + clouddiskrdbStore_->rdbStore_ = rdb; + auto transaction = make_shared(); + std::shared_ptr rset = std::make_shared(); + EXPECT_CALL(*transaction, QueryByStep(An(), + An &>(), preCount)).WillOnce(Return(ByMove(rset))); + EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*rset, GetLong(_, _)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_RDB)); + + int32_t ret = clouddiskrdbStore_->GetRecycleInfo(transaction, cloudId, rowId, position, attr, dirtyType); + EXPECT_EQ(ret, E_RDB); +} + /** * @tc.name: FavoriteSetXattr * @tc.desc: Verify the CloudDiskRdbStore::FavoriteSetXattr function @@ -2043,7 +2078,7 @@ HWTEST_F(CloudDiskRdbStoreTest, FavoriteSetXattrTest4, TestSize.Level1) auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; EXPECT_CALL(*rdb, Update(_, _, _, _, An &>())).WillOnce(Return(E_OK)); - + int32_t ret = clouddiskrdbStore_->FavoriteSetXattr(cloudId, value); EXPECT_EQ(ret, E_OK); } @@ -2681,9 +2716,10 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest1, TestSize.Level1) const std::string cloudId = ""; std::string value = ""; int32_t pos = 0; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_INVAL_ARG); } @@ -2697,9 +2733,10 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest2, TestSize.Level1) const std::string cloudId = "rootId"; std::string value = ""; int32_t pos = 0; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_INVAL_ARG); } @@ -2713,13 +2750,14 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest3, TestSize.Level1) const std::string cloudId = "100"; std::string value = "mock"; int32_t pos = 0; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); bool preCount = true; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(nullptr))); - - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_RDB); } @@ -2733,6 +2771,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest4, TestSize.Level1) const std::string cloudId = "100"; std::string value = ""; int32_t pos = 0; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); bool preCount = true; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; @@ -2740,8 +2779,8 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest4, TestSize.Level1) EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_RDB)); - - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_RDB); } @@ -2756,6 +2795,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest5, TestSize.Level1) std::string value = "mock"; int32_t pos = 0; bool preCount = true; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; std::shared_ptr rset = std::make_shared(); @@ -2763,8 +2803,8 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest5, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_RDB)); - - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_RDB); } @@ -2778,6 +2818,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest6, TestSize.Level1) const std::string cloudId = "100"; std::string value = ""; int32_t pos = -1; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); bool preCount = true; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; @@ -2787,8 +2828,8 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest6, TestSize.Level1) EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_RDB)); - - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_RDB); } @@ -2802,6 +2843,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest7, TestSize.Level1) const std::string cloudId = "100"; std::string value = ""; int32_t pos = -1; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); bool preCount = true; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; @@ -2811,8 +2853,8 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest7, TestSize.Level1) EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_OK)); - - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_OK); } @@ -2826,6 +2868,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest8, TestSize.Level1) const std::string cloudId = "100"; std::string value = ""; int32_t pos = 1; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); bool preCount = true; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; @@ -2833,11 +2876,36 @@ HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest8, TestSize.Level1) EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); - - int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos); + + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); EXPECT_EQ(ret, E_OK); } +/** + * @tc.name: GetExtAttr + * @tc.desc: Verify the CloudDiskRdbStore::ExtAttributeSetXattr function + * @tc.type: FUNC + */ +HWTEST_F(CloudDiskRdbStoreTest, GetExtAttrTest9, TestSize.Level1) +{ + const std::string cloudId = "100"; + std::string value = ""; + int32_t pos = 1; + int32_t dirtyType = static_cast(DirtyType::TYPE_SYNCED); + bool preCount = true; + auto rdb = make_shared(); + clouddiskrdbStore_->rdbStore_ = rdb; + std::shared_ptr rset = std::make_shared(); + EXPECT_CALL(*rdb, QueryByStep(An(), + An &>(), preCount)).WillOnce(Return(ByMove(rset))); + EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_OK)); + EXPECT_CALL(*rset, GetInt(_, _)).WillOnce(Return(E_OK)).WillOnce(Return(E_RDB)); + + int32_t ret = clouddiskrdbStore_->GetExtAttr(cloudId, value, pos, dirtyType); + EXPECT_EQ(ret, E_RDB); +} + /** * @tc.name: GetXAttr * @tc.desc: Verify the CloudDiskRdbStore::GetXAttr function @@ -3165,7 +3233,7 @@ HWTEST_F(CloudDiskRdbStoreTest, RenameTest2, TestSize.Level1) const std::string newFileName = "newFileName"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->Rename(oldParentCloudId, oldFileName, newParentCloudId, newFileName); EXPECT_EQ(ret, E_INVAL_ARG); } @@ -3183,7 +3251,7 @@ HWTEST_F(CloudDiskRdbStoreTest, RenameTest3, TestSize.Level1) const std::string newFileName = "newFileName"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->Rename(oldParentCloudId, oldFileName, newParentCloudId, newFileName); EXPECT_EQ(ret, E_INVAL_ARG); } @@ -3201,7 +3269,7 @@ HWTEST_F(CloudDiskRdbStoreTest, RenameTest4, TestSize.Level1) const std::string newFileName = "newFileName"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->Rename(oldParentCloudId, oldFileName, newParentCloudId, newFileName); EXPECT_EQ(ret, E_INVAL_ARG); } @@ -3219,7 +3287,7 @@ HWTEST_F(CloudDiskRdbStoreTest, RenameTest5, TestSize.Level1) const std::string newFileName = "newFileName"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->Rename(oldParentCloudId, oldFileName, newParentCloudId, newFileName); EXPECT_EQ(ret, EINVAL); } @@ -3237,7 +3305,7 @@ HWTEST_F(CloudDiskRdbStoreTest, RenameTest6, TestSize.Level1) const std::string newFileName = ".."; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->Rename(oldParentCloudId, oldFileName, newParentCloudId, newFileName); EXPECT_EQ(ret, EINVAL); } @@ -3255,7 +3323,7 @@ HWTEST_F(CloudDiskRdbStoreTest, RenameTest7, TestSize.Level1) const std::string newFileName = "mock"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->Rename(oldParentCloudId, oldFileName, newParentCloudId, newFileName); EXPECT_EQ(ret, EINVAL); } @@ -3273,7 +3341,7 @@ HWTEST_F(CloudDiskRdbStoreTest, RenameTest8, TestSize.Level1) const std::string newFileName = "mock"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->Rename(oldParentCloudId, oldFileName, newParentCloudId, newFileName); EXPECT_EQ(ret, EINVAL); } @@ -3579,7 +3647,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetCurNodeTest2, TestSize.Level1) clouddiskrdbStore_->rdbStore_ = rdb; EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(nullptr))); - + int32_t ret = clouddiskrdbStore_->GetCurNode(cloudId, curNode); EXPECT_EQ(ret, E_RDB); } @@ -3600,7 +3668,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetCurNodeTest3, TestSize.Level1) EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_RDB)); - + int32_t ret = clouddiskrdbStore_->GetCurNode(cloudId, curNode); EXPECT_EQ(ret, E_RDB); } @@ -3622,7 +3690,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetCurNodeTest4, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetRow(_)).WillRepeatedly(Return(E_RDB)); - + int32_t ret = clouddiskrdbStore_->GetCurNode(cloudId, curNode); EXPECT_EQ(ret, E_RDB); } @@ -3644,7 +3712,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetCurNodeTest5, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetRow(_)).WillRepeatedly(Return(E_OK)); - + int32_t ret = clouddiskrdbStore_->GetCurNode(cloudId, curNode); EXPECT_EQ(ret, E_OK); } @@ -3661,7 +3729,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetParentNodeTest1, TestSize.Level1) std::string fileName = "test"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->GetParentNode(parentCloudId, nextCloudId, fileName); EXPECT_EQ(ret, E_INVAL_ARG); } @@ -3681,7 +3749,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetParentNodeTest2, TestSize.Level1) clouddiskrdbStore_->rdbStore_ = rdb; EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(nullptr))); - + int32_t ret = clouddiskrdbStore_->GetParentNode(parentCloudId, nextCloudId, fileName); EXPECT_EQ(ret, E_RDB); } @@ -3703,7 +3771,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetParentNodeTest3, TestSize.Level1) EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_RDB)); - + int32_t ret = clouddiskrdbStore_->GetParentNode(parentCloudId, nextCloudId, fileName); EXPECT_EQ(ret, E_RDB); } @@ -3726,7 +3794,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetParentNodeTest4, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetRow(_)).WillRepeatedly(Return(E_RDB)); - + int32_t ret = clouddiskrdbStore_->GetParentNode(parentCloudId, nextCloudId, fileName); EXPECT_EQ(ret, E_RDB); } @@ -3749,7 +3817,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetParentNodeTest5, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetRow(_)).WillRepeatedly(Return(E_OK)); - + int32_t ret = clouddiskrdbStore_->GetParentNode(parentCloudId, nextCloudId, fileName); EXPECT_EQ(ret, E_OK); } @@ -3765,7 +3833,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetUriFromDBTest1, TestSize.Level1) std::string uri = "100"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->GetUriFromDB(parentCloudId, uri); EXPECT_EQ(ret, E_OK); } @@ -3781,7 +3849,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetUriFromDBTest2, TestSize.Level1) std::string uri = "100"; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->GetUriFromDB(parentCloudId, uri); EXPECT_EQ(ret, E_OK); } @@ -3800,7 +3868,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetUriFromDBTest3, TestSize.Level1) clouddiskrdbStore_->rdbStore_ = rdb; EXPECT_CALL(*rdb, QueryByStep(An(), An &>(), preCount)).WillOnce(Return(ByMove(nullptr))); - + int32_t ret = clouddiskrdbStore_->GetUriFromDB(parentCloudId, uri); EXPECT_EQ(ret, E_RDB); } @@ -3823,7 +3891,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetUriFromDBTest4, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillOnce(Return(E_OK)).WillRepeatedly(Return(E_RDB)); EXPECT_CALL(*rset, GetRow(_)).WillRepeatedly(Return(E_OK)); - + int32_t ret = clouddiskrdbStore_->GetUriFromDB(parentCloudId, uri); EXPECT_EQ(ret, E_OK); } @@ -3846,7 +3914,7 @@ HWTEST_F(CloudDiskRdbStoreTest, GetUriFromDBTest5, TestSize.Level1) An &>(), preCount)).WillOnce(Return(ByMove(rset))); EXPECT_CALL(*rset, GoToNextRow()).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetRow(_)).WillRepeatedly(Return(E_OK)); - + int32_t ret = clouddiskrdbStore_->GetUriFromDB(parentCloudId, uri); EXPECT_EQ(ret, E_OK); } @@ -4060,7 +4128,7 @@ HWTEST_F(CloudDiskRdbStoreTest, CreateDentryFileTest1, TestSize.Level1) std::string destParentCloudId = ""; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->CreateDentryFile(metaBase, destParentCloudId); EXPECT_EQ(ret, E_RDB); } @@ -4076,7 +4144,7 @@ HWTEST_F(CloudDiskRdbStoreTest, CreateDentryFileTest2, TestSize.Level1) std::string destParentCloudId = ""; auto rdb = make_shared(); clouddiskrdbStore_->rdbStore_ = rdb; - + int32_t ret = clouddiskrdbStore_->CreateDentryFile(metaBase, destParentCloudId); EXPECT_EQ(ret, E_OK); } @@ -4101,7 +4169,7 @@ HWTEST_F(CloudDiskRdbStoreTest, InsertCopyDataTest1, TestSize.Level1) EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*transaction, Insert(_, _, _)).WillOnce(Return(std::make_pair(E_RDB, 0))); - + int32_t ret = clouddiskrdbStore_->InsertCopyData(srcCloudId, destCloudId, destParentCloudId, rset); EXPECT_EQ(ret, E_RDB); } @@ -4149,7 +4217,7 @@ HWTEST_F(CloudDiskRdbStoreTest, InsertCopyDataTest3, TestSize.Level1) EXPECT_CALL(*rset, GetInt(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*rset, GetString(_, _)).WillRepeatedly(Return(E_OK)); EXPECT_CALL(*transaction, Insert(_, _, _)).WillOnce(Return(std::make_pair(E_OK, 0))); - + int32_t ret = clouddiskrdbStore_->InsertCopyData(srcCloudId, destCloudId, destParentCloudId, rset); EXPECT_EQ(ret, E_OK); }