diff --git a/test/unittests/clouddiskservice/BUILD.gn b/test/unittests/clouddiskservice/BUILD.gn index bb40b775a90255e4a2164f597748871681277a85..795ab36977a06bb5e95d9723eea79a97147530dc 100644 --- a/test/unittests/clouddiskservice/BUILD.gn +++ b/test/unittests/clouddiskservice/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. +# Copyright (C) 2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -14,6 +14,318 @@ import("//build/test.gni") import("//foundation/filemanagement/dfs_service/distributedfile.gni") +ohos_unittest("cloud_disk_service_logfile_static_test") { + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${distributedfile_path}/test/unittests/clouddiskservice/mock/system_function_mock.cpp", + "${services_path}/clouddiskservice/sync_folder/src/convertor.cpp", + "${distributedfile_path}/utils/log/src/utils_log.cpp", + "${distributedfile_path}/utils/system/src/utils_directory.cpp", + "${distributedfile_path}/test/unittests/clouddiskservice/mock/cloud_disk_service_metafile_mock.cpp", + "sync_folder/cloud_disk_service_logfile_static_test.cpp", + ] + + include_dirs = [ + "${services_path}/clouddiskservice/sync_folder/src", + "${services_path}/clouddiskservice/sync_folder/include", + "${distributedfile_path}/test/unittests/clouddiskservice/mock", + "${innerkits_native_path}/clouddiskservice_kit_inner", + "${services_path}/clouddiskservice/monitor/include", + "${services_path}/clouddiskservice/ipc/include", + "${services_path}/clouddiskservice/utils/include", + "${distributedfile_path}/utils/inner_api", + "${distributedfile_path}/utils/system/include", + "${distributedfile_path}/interfaces/inner_api/native/clouddiskservice_kit_inner", + "${distributedfile_path}/utils/dentry/include", + "${distributedfile_path}/utils/log/include", + ] + + deps = [ + + ] + + external_deps = [ + "e2fsprogs:libext2_uuid", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "c_utils:utils", + "ffrt:libffrt", + "json:nlohmann_json_static", + "libfuse:libfuse", + "hisysevent:libhisysevent", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD003900", + "LOG_TAG=\"CloudDiskService\"", + ] + + public_configs = [ + "${services_path}/clouddiskservice:cloud_disk_service_public_config", + ] + + if (cloudsync_service_hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + use_exceptions = true +} + +ohos_unittest("cloud_disk_service_logfile_test") { + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${services_path}/clouddiskservice/sync_folder/src/convertor.cpp", + "${services_path}/clouddiskservice/ipc/src/cloud_disk_service_callback_manager.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp", + "${distributedfile_path}/test/unittests/clouddiskservice/mock/cloud_disk_service_manager_mock.cpp", + "${distributedfile_path}/test/unittests/clouddiskservice/mock/cloud_disk_service_metafile_mock.cpp", + "${services_path}/clouddiskservice/sync_folder/src/uuid_helper.cpp", + "${distributedfile_path}/test/unittests/clouddiskservice/mock/system_function_mock.cpp", + "sync_folder/cloud_disk_service_logfile_test.cpp", + ] + + include_dirs = [ + "${services_path}/clouddiskservice/sync_folder/include", + "${services_path}/clouddiskservice/sync_folder/src", + "${innerkits_native_path}/clouddiskservice_kit_inner", + "${services_path}/clouddiskservice/monitor/include", + "${services_path}/clouddiskservice/ipc/include", + "${services_path}/clouddiskservice/utils/include", + "${distributedfile_path}/utils/inner_api", + "${distributedfile_path}/utils/dentry/include", + "${distributedfile_path}/utils/system/include", + "${distributedfile_path}/test/unittests/clouddiskservice/mock", + ] + + deps = [ + "${utils_path}:libdistributedfileutils_lite", + ] + + external_deps = [ + "e2fsprogs:libext2_uuid", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "c_utils:utils", + "ffrt:libffrt", + "json:nlohmann_json_static", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD003900", + "LOG_TAG=\"CloudDiskService\"", + ] + + public_configs = [ + "${services_path}/clouddiskservice:cloud_disk_service_public_config", + ] + + use_exceptions = true +} + +ohos_unittest("cloud_disk_service_metafile_test") { + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${distributedfile_path}/test/unittests/clouddiskservice/mock/system_function_mock.cpp", + "${distributedfile_path}/utils/log/src/utils_log.cpp", + "${services_path}/clouddiskservice/sync_folder/src/cloud_disk_service_metafile.cpp", + "${services_path}/clouddiskservice/sync_folder/src/convertor.cpp", + "sync_folder/cloud_disk_service_metafile_test.cpp", + ] + + include_dirs = [ + "${distributedfile_path}/test/unittests/clouddiskservice/mock", + "${distributedfile_path}/utils/dentry/include", + "${services_path}/clouddiskservice/sync_folder/include", + "${services_path}/clouddiskservice/utils/include", + ] + + deps = [ + "${utils_path}:libdistributedfileutils_lite", + ] + + external_deps = [ + "e2fsprogs:libext2_uuid", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "json:nlohmann_json_static", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD003900", + "LOG_TAG=\"CloudDiskService\"", + ] + + use_exceptions = true +} + +ohos_unittest("cloud_disk_service_metafile_static_test") { + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${distributedfile_path}/test/unittests/clouddiskservice/mock/system_function_mock.cpp", + "${distributedfile_path}/utils/log/src/utils_log.cpp", + "${services_path}/clouddiskservice/sync_folder/src/convertor.cpp", + "sync_folder/cloud_disk_service_metafile_static_test.cpp", + ] + + include_dirs = [ + "${distributedfile_path}/test/unittests/clouddiskservice/mock", + "${distributedfile_path}/utils/dentry/include", + "${services_path}/clouddiskservice/sync_folder/include", + "${services_path}/clouddiskservice/sync_folder/src", + "${services_path}/clouddiskservice/utils/include", + ] + + deps = [ + "${utils_path}:libdistributedfileutils_lite", + ] + + external_deps = [ + "e2fsprogs:libext2_uuid", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "json:nlohmann_json_static", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD004308", + "LOG_TAG=\"CloudDiskService\"", + ] + + use_exceptions = true +} + +ohos_unittest("cloud_disk_service_syncfolder_test") { + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${services_path}/clouddiskservice/sync_folder/src/cloud_disk_service_logfile.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager.cpp", + "${services_path}/clouddiskservice/sync_folder/src/cloud_disk_service_metafile.cpp", + "${services_path}/clouddiskservice/sync_folder/src/uuid_helper.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp", + "${services_path}/clouddiskservice/ipc/src/cloud_disk_service_callback_manager.cpp", + "${services_path}/clouddiskservice/sync_folder/src/convertor.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager_impl.cpp", + "sync_folder/cloud_disk_service_syncfolder_test.cpp", + ] + + include_dirs = [ + "${services_path}/clouddiskservice/sync_folder/src", + "${services_path}/clouddiskservice/sync_folder/include", + "${services_path}/clouddiskservice/monitor/include", + "${innerkits_native_path}/clouddiskservice_kit_inner", + "${services_path}/clouddiskservice/ipc/include", + "${services_path}/clouddiskservice/utils/include", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/include", + ] + + deps = [ + "${utils_path}:libdistributedfileutils_lite", + ] + + external_deps = [ + "e2fsprogs:libext2_uuid", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "c_utils:utils", + "ffrt:libffrt", + "json:nlohmann_json_static", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD003900", + "LOG_TAG=\"CloudDiskService\"", + ] + + public_configs = [ + "${services_path}/clouddiskservice:cloud_disk_service_public_config", + ] + + use_exceptions = true +} + +ohos_unittest("convertor_test") { + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${distributedfile_path}/utils/log/src/utils_log.cpp", + "${services_path}/clouddiskservice/sync_folder/src/convertor.cpp", + "sync_folder/convertor_test.cpp", + ] + + include_dirs = [ + "${services_path}/clouddiskservice/sync_folder/include", + "${services_path}/clouddiskservice/utils/include", + ] + + deps = [ + "${utils_path}:libdistributedfileutils_lite", + ] + + external_deps = [ + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD003900", + "LOG_TAG=\"CloudDiskService\"", + ] + + use_exceptions = true +} + +ohos_unittest("uuid_helper_test") { + module_out_path = "dfs_service/dfs_service" + + sources = [ + "${distributedfile_path}/utils/log/src/utils_log.cpp", + "${services_path}/clouddiskservice/sync_folder/src/uuid_helper.cpp", + "sync_folder/uuid_helper_test.cpp", + ] + + include_dirs = [ + "${services_path}/clouddiskservice/sync_folder/include", + "${services_path}/clouddiskservice/utils/include", + ] + + deps = [ + "${utils_path}:libdistributedfileutils_lite", + ] + + external_deps = [ + "e2fsprogs:libext2_uuid", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + ] + + defines = [ + "private=public", + "LOG_DOMAIN=0xD003900", + "LOG_TAG=\"CloudDiskService\"", + ] + + use_exceptions = true +} + ohos_unittest("disk_monitor_test") { module_out_path = "dfs_service/dfs_service" @@ -89,5 +401,12 @@ group("clouddisk_service_test") { deps = [ ":disk_monitor_test", ":disk_utils_test", + ":cloud_disk_service_logfile_static_test", + ":cloud_disk_service_logfile_test", + ":cloud_disk_service_metafile_test", + ":cloud_disk_service_metafile_static_test", + ":cloud_disk_service_syncfolder_test", + ":convertor_test", + ":uuid_helper_test", ] -} \ No newline at end of file +} diff --git a/test/unittests/clouddiskservice/mock/assistant.h b/test/unittests/clouddiskservice/mock/assistant.h index 6280dd319ba94499c54edcbed768e12b3b1b0d5c..89af9eef50e43aa99acb1cc4813c62947fa5f7ac 100644 --- a/test/unittests/clouddiskservice/mock/assistant.h +++ b/test/unittests/clouddiskservice/mock/assistant.h @@ -19,12 +19,25 @@ #include namespace OHOS::FileManagement::CloudDiskService { + class Assistant { public: static inline std::shared_ptr ins = nullptr; virtual ~Assistant() = default; - virtual ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) = 0; + virtual ssize_t readlink(const char *pathname, char *buf, size_t bufsize) = 0; + virtual int fstat(int fd, struct stat *buf) = 0; + virtual int ftruncate(int fd, off_t length) = 0; + + // file_utils + virtual int64_t ReadFile(int fd, off_t offset, size_t size, void *data) = 0; + virtual int64_t WriteFile(int fd, const void *data, off_t offset, size_t size) = 0; + virtual int FilePosLock(int fd, off_t offset, size_t size, int type) = 0; + + virtual int access(const char *name, int type) = 0; + virtual struct dirent* readdir(DIR* d) = 0; + virtual int MockStat(const char* path, struct stat* buf); + virtual int fanotify_init(unsigned flags, unsigned event_f_flags) = 0; virtual int fanotify_mark(int fanotify_fd, unsigned flags, unsigned long long mask, int dfd, const char *pathname) = 0; @@ -35,11 +48,23 @@ public: class AssistantMock : public Assistant { public: MOCK_METHOD3(readlink, ssize_t(const char *, char *, size_t)); + MOCK_METHOD2(fstat, int(int, struct stat *)); + MOCK_METHOD2(ftruncate, int(int, off_t)); + + // file_utils + MOCK_METHOD4(ReadFile, int64_t(int fd, off_t offset, size_t size, void *data)); + MOCK_METHOD4(WriteFile, int64_t(int fd, const void *data, off_t offset, size_t size)); + MOCK_METHOD4(FilePosLock, int(int fd, off_t offset, size_t size, int type)); + + MOCK_METHOD2(access, int(const char *, int)); + MOCK_METHOD1(opendir, DIR*(const char*)); + MOCK_METHOD1(readdir, struct dirent*(DIR*)); + MOCK_METHOD2(MockStat, int(const char*, struct stat*)); + MOCK_METHOD2(fanotify_init, int(unsigned, unsigned)); MOCK_METHOD5(fanotify_mark, int(int, unsigned, unsigned long long, int, const char *)); - MOCK_METHOD1(opendir, DIR *(const char *)); MOCK_METHOD1(dirfd, int(DIR *)); }; -} // namespace OHOS::FileManagement::CloudDiskService +} #endif // TEST_UNITTEST_CLOUD_DISK_SERVICE_ASSISTANT_H diff --git a/test/unittests/clouddiskservice/mock/cloud_disk_service_manager_mock.cpp b/test/unittests/clouddiskservice/mock/cloud_disk_service_manager_mock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f41144f0594d35c475578fc7bd958d47ff7157b --- /dev/null +++ b/test/unittests/clouddiskservice/mock/cloud_disk_service_manager_mock.cpp @@ -0,0 +1,24 @@ +/* + * 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 "cloud_disk_service_manager_mock.h" + +namespace OHOS::FileManagement::CloudDiskService { + +CloudDiskServiceManager &CloudDiskServiceManager::GetInstance() +{ + return Test::CloudDiskServiceManagerMock::GetInstance(); +} +} \ No newline at end of file diff --git a/test/unittests/clouddiskservice/mock/cloud_disk_service_manager_mock.h b/test/unittests/clouddiskservice/mock/cloud_disk_service_manager_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..e4db1bf35b570c20df34ac413064c4f206d70cd2 --- /dev/null +++ b/test/unittests/clouddiskservice/mock/cloud_disk_service_manager_mock.h @@ -0,0 +1,49 @@ +/* + * 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. + */ +#ifndef TEST_UNITTEST_CLOUD_DISK_SERVICE_MANAGER_MOCK_H +#define TEST_UNITTEST_CLOUD_DISK_SERVICE_MANAGER_MOCK_H + +#include "cloud_disk_service_manager.h" + +#include +#include + +namespace OHOS::FileManagement::CloudDiskService::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class CloudDiskServiceManagerMock final : public CloudDiskServiceManager { +public: + static CloudDiskServiceManagerMock &GetInstance() + { + static CloudDiskServiceManageMock instance; + return instance; + } + + MOCK_METHOD2(RegisterSyncFolderChanges, int32_t(const std::string &, + const std::shared_ptr)); + MOCK_METHOD1(UnregisterSyncFolderChanges, int32_t(const std::string &)); + MOCK_METHOD4(GetSyncFolderChanges, int32_t(const std::string &, uint64_t, uint64_t, ChangesResult &)); + MOCK_METHOD3(SetFileSyncStates, int32_t(const std::string &, + const std::vector &, std::vector &)); + MOCK_METHOD3(GetFileSyncStates, int32_t(const std::string &, const std::vector &, std::vector &)); + MOCK_METHOD3(RegisterSyncFolder, int32_t(int32_t, const std::string &, const std::string &)); + MOCK_METHOD3(UnregisterSyncFolder, int32_t(int32_t, const std::string &, const std::string &)); + MOCK_METHOD1(UnregisterForSa, int32_t(const string&)); +}; +} + +#endif \ No newline at end of file diff --git a/test/unittests/clouddiskservice/mock/cloud_disk_service_metafile_mock.cpp b/test/unittests/clouddiskservice/mock/cloud_disk_service_metafile_mock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..162041225d35f39ed6c29700d3584a1b8af2636b --- /dev/null +++ b/test/unittests/clouddiskservice/mock/cloud_disk_service_metafile_mock.cpp @@ -0,0 +1,105 @@ +/* + * 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 "cloud_disk_service_metafile.h" + +namespace OHOS::FileManagement::CloudDiskService { +#ifndef E_OK +#define E_OK 0 +#endif + +CloudDiskServiceMetaFile::CloudDiskServiceMetaFile(const uint32_t userId, const uint32_t syncFolderIndex, + const uint64_t inode) +{ + userId_ = userId; +} + +MetaFileMgr& MetaFileMgr::GetInstance() +{ + static MetaFileMgr instance_; + return instance_; +} + +std::shared_ptr MetaFileMgr::GetCloudDiskServiceMetaFile(uint32_t userId, + const uint32_t syncFolderIndex, const uint64_t inode) +{ + std::shared_ptr metaFile = + std::make_shared(userId, syncFolderIndex, inode); + return metaFile; +} + +int32_t CloudDiskServiceMetaFile::DoRemove(const MetaBase &base, std::string &recordId) +{ + if (recordId == "") { + return E_OK; + } else { + return 1; + } +} + +int32_t CloudDiskServiceMetaFile::DoRenameOld(const MetaBase &base, std::string &recordId) +{ + if (recordId == "") { + return E_OK; + } else { + return 1; + } +} + +int32_t CloudDiskServiceMetaFile::DoRenameNew(const MetaBase &base, std::string &recordId) +{ + if (recordId == "") { + return E_OK; + } else { + return 1; + } +} + +int32_t MetaFileMgr::GetRelativePath(const std::shared_ptr metaFile, std::string &path) +{ + if (metaFile->userId_ == 1) { + return E_OK; + } else { + return -1; + } +} + +int32_t CloudDiskServiceMetaFile::DoUpdate(const MetaBase &base, std::string &recordId) +{ + if(recordId == "") { + return E_OK; + } else { + return 1; + } +} + +int32_t CloudDiskServiceMetaFile::GenericDentryHeader() +{ + return E_OK; +} + +int32_t CloudDiskServiceMetaFile::DoCreate(const MetaBase &base) +{ + if (base.name == "") { + return E_OK; + } else { + return 1; + } +} + +int32_t CloudDiskServiceMetaFile::DoLookupByRecordId(MetaBase &base) +{ + return E_OK; +} +} \ No newline at end of file diff --git a/test/unittests/clouddiskservice/mock/system_function_mock.cpp b/test/unittests/clouddiskservice/mock/system_function_mock.cpp index b10d5a4608f42618cd4eae6fd49aa5ee6f410c89..b143ac2d974b8bb4e12b52ddc5416b9c974a88d3 100644 --- a/test/unittests/clouddiskservice/mock/system_function_mock.cpp +++ b/test/unittests/clouddiskservice/mock/system_function_mock.cpp @@ -13,15 +13,11 @@ * limitations under the License. */ #include "assistant.h" +#include "file_utils.h" #include using namespace OHOS::FileManagement::CloudDiskService; -ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) -{ - return Assistant::ins->readlink(pathname, buf, bufsiz); -} - int fanotify_init(unsigned flags, unsigned event_f_flags) { return Assistant::ins->fanotify_init(flags, event_f_flags); @@ -36,12 +32,49 @@ int fanotify_mark(int fanotify_fd, return Assistant::ins->fanotify_mark(fanotify_fd, flags, mask, dfd, pathname); } +int dirfd(DIR *d) +{ + return Assistant::ins->dirfd(d); +} + +ssize_t readlink(const char *pathname, char *buf, size_t bufsize) +{ + return Assistant::ins->readlink(pathname, buf, bufsize); +} + +int fstat(int fd, struct stat *buf) +{ + return Assistant::ins->fstat(fd, buf); +} + +int ftruncate(int fd, off_t length) +{ + return Assistant::ins->ftruncate(fd, length); +} + DIR* opendir(const char* path) { return Assistant::ins->opendir(path); } -int dirfd(DIR *d) +struct dirent* readdir(DIR* d) { - return Assistant::ins->dirfd(d); + return Assistant::ins->readdir(d); +} + +namespace OHOS::FileManagement { +int64_t FileUtils::ReadFile(int fd, off_t offset, size_t size, void *data) +{ + return Assistant::ins->ReadFile(fd, offset, size, data); +} + +int64_t FileUtils::WriteFile(int fd, const void *data, off_t offset, size_t size) +{ + return Assistant::ins->WriteFile(fd, data, offset, size); +} + +int FileRangeLock::FilePosLock(int fd, off_t offset, size_t size, int type) +{ + return Assistant::ins->FilePosLock(fd, offset, size, type); } +} // namespace OHOS::FileManagement diff --git a/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_logfile_static_test.cpp b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_logfile_static_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec700847dbd1630b44b7addf0079c6509096c8b4 --- /dev/null +++ b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_logfile_static_test.cpp @@ -0,0 +1,327 @@ +/* + * 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 "cloud_disk_service_logfile.cpp" + +#include +#include + +#include "assistant.h" + +namespace OHOS::FileManagement::CloudDiskService::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class CloudDiskServiceLogFileStaticTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr insMock_; +}; + +void CloudDiskServiceLogFileStaticTest::SetUpTestCase(void) { + GTEST_LOG_(INFO) << "SetUpTestCase"; + insMock_ = make_shared(); + Assistant::ins = insMock_; +} + +void CloudDiskServiceLogFileStaticTest::TearDownTestCase(void) { + GTEST_LOG_(INFO) << "TearDownTestCase"; + insMock_ = nullptr; + Assistant::ins = nullptr; +} + +void CloudDiskServiceLogFileStaticTest::SetUp() { + +} + +void CloudDiskServiceLogFileStaticTest::TearDown() { + +} + +/** + * @tc.name: GetLogFileByPathTest001 + * @tc.desc: Verify the GetLogFileByPath function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, GetLogFileByPathTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetLogFileByPathTest001 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 1; + string res = GetLogFileByPath(userId, syncFolderIndex); + string str = + "/data/service/el2/1/hmdfs/cache/account_cache/dentry_cache/" + "clouddisk_service_cache/0000000000000001/history.log"; + EXPECT_EQ(res, str); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetLogFileByPathTest001 failed"; + } + GTEST_LOG_(INFO) << "GetLogFileByPathTest001 end"; +} + +/** + * @tc.name: GetBucketAndOffsetTest001 + * @tc.desc: Verify the GetBucketAndOffset function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, GetBucketAndOffsetTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBucketAndOffsetTest001 start"; + try { + uint64_t line = 1; + uint32_t bucket = 1; + uint32_t offset = 1; + GetBucketAndOffset(line, bucket, offset); + EXPECT_EQ(bucket, 0); + EXPECT_EQ(offset, 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBucketAndOffsetTest001 failed"; + } + GTEST_LOG_(INFO) << "GetBucketAndOffsetTest001 end"; +} + +/** + * @tc.name: GetBucketaddrTest001 + * @tc.desc: Verify the GetBucketaddr function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, GetBucketaddrTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBucketaddrTest001 start"; + try { + uint32_t bucket = 1; + auto res = GetBucketaddr(bucket); + EXPECT_EQ(res, 8192); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBucketaddrTest001 failed"; + } + GTEST_LOG_(INFO) << "GetBucketaddrTest001 end"; +} + +/** + * @tc.name: LoadCurrentPageTest001 + * @tc.desc: Verify the LoadCurrentPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, LoadCurrentPageTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LoadCurrentPageTest001 start"; + try { + int fd = 1; + uint32_t bucket = 1; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillOnce(Return(1)); + auto res = LoadCurrentPage(fd, bucket); + EXPECT_EQ(res, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "LoadCurrentPageTest001 failed"; + } + GTEST_LOG_(INFO) << "LoadCurrentPageTest001 end"; +} + +/** + * @tc.name: LoadCurrentPageTest002 + * @tc.desc: Verify the LoadCurrentPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, LoadCurrentPageTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LoadCurrentPageTest002 start"; + try { + int fd = 1; + uint32_t bucket = 1; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillOnce(Return(0)) + .WillOnce(Return(1)); + EXPECT_CALL(*insMock_, ReadFile(_, _, _, _)).WillOnce(Return(1)); + auto res = LoadCurrentPage(fd, bucket); + EXPECT_EQ(res, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "LoadCurrentPageTest002 failed"; + } + GTEST_LOG_(INFO) << "LoadCurrentPageTest002 end"; +} + +/** + * @tc.name: LoadCurrentPageTest003 + * @tc.desc: Verify the LoadCurrentPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, LoadCurrentPageTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LoadCurrentPageTest003 start"; + try { + int fd = 1; + uint32_t bucket = 1; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillRepetedly(Return(0)); + EXPECT_CALL(*insMock_, ReadFile(_, _, _, _)).WillOnce(Return(LOGGROUP_SIZE)); + auto res = LoadCurrentPage(fd, bucket); + EXPECT_NE(res, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "LoadCurrentPageTest003 failed"; + } + GTEST_LOG_(INFO) << "LoadCurrentPageTest003 end"; +} + +/** + * @tc.name: UnlockCurrentPageTest001 + * @tc.desc: Verify the UnlockCurrentPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, UnlockCurrentPageTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnlockCurrentPageTest001 start"; + try { + int fd = 1; + uint32_t bucket = 1; + UnlockCurrentPage(fd, bucket); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "UnlockCurrentPageTest001 failed"; + } + GTEST_LOG_(INFO) << "UnlockCurrentPageTest001 end"; +} + +/** + * @tc.name: SyncCurrentPageTest001 + * @tc.desc: Verify the SyncCurrentPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, SyncCurrentPageTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SyncCurrentPageTest001 start"; + try { + LogGroup logGroup; + int fd = 1; + uint32_t line = 1; + EXPECT_CALL(*insMock_, ReadFile(_, _, _, _)).WillOnce(Return(1)); + auto res = SyncCurrentPage(logGroup, fd, line); + EXPECT_EQ(res, EINVAL); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SyncCurrentPageTest001 failed"; + } + GTEST_LOG_(INFO) << "SyncCurrentPageTest001 end"; +} + +/** + * @tc.name: SyncCurrentPageTest002 + * @tc.desc: Verify the SyncCurrentPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, SyncCurrentPageTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SyncCurrentPageTest002 start"; + try { + LogGroup logGroup; + int fd = 1; + uint32_t line = 1; + EXPECT_CALL(*insMock_, WriteFile(_, _, _, _)).WillOnce(Return(LOGGROUP_SIZE)); + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillOnce(Return(1)); + auto res = SyncCurrentPage(logGroup, fd, line); + EXPECT_EQ(res, 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SyncCurrentPageTest002 failed"; + } + GTEST_LOG_(INFO) << "SyncCurrentPageTest002 end"; +} + +/** + * @tc.name: SyncCurrentPageTest003 + * @tc.desc: Verify the SyncCurrentPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, SyncCurrentPageTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SyncCurrentPageTest003 start"; + try { + LogGroup logGroup; + int fd = 1; + uint32_t line = 1; + EXPECT_CALL(*insMock_, WriteFile(_, _, _, _)).WillOnce(Return(LOGGROUP_SIZE)); + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillOnce(Return(0)); + auto res = SyncCurrentPage(logGroup, fd, line); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SyncCurrentPageTest003 failed"; + } + GTEST_LOG_(INFO) << "SyncCurrentPageTest003 end"; +} + +/** + * @tc.name: FillLogGroupTest001 + * @tc.desc: Verify the FillLogGroup function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, FillLogGroupTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FillLogGroupTest001 start"; + try { + LogGroup logGroup; + LogBlock logBlock; + uint32_t offset = 0; + logGroup.nsl[0].timestamp = 1; + auto res = FillLogGroup(logGroup, logBlock, offset); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FillLogGroupTest001 failed"; + } + GTEST_LOG_(INFO) << "FillLogGroupTest001 end"; +} + +/** + * @tc.name: GetCurrentLineTest001 + * @tc.desc: Verify the GetCurrentLine function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileStaticTest, GetCurrentLineTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetCurrentLineTest001 start"; + try { + int fd = 1; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillOnce(Return(1)) + .WillRepeatedly(Return(0)); + EXPECT_CALL(*insMock_, ReadFile(_, _, _, _)).WillRepeatedly(Return(4096)); + GetCurrentLine(fd); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetCurrentLineTest001 failed"; + } + GTEST_LOG_(INFO) << "GetCurrentLineTest001 end"; +} +} \ No newline at end of file diff --git a/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_logfile_test.cpp b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_logfile_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..52bc7a99cd9be1d57bdebcf733ea392e2a1e8474 --- /dev/null +++ b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_logfile_test.cpp @@ -0,0 +1,1562 @@ +/* + * 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 "cloud_disk_service_logfile.h" + +#include +#include + +#include "assistant.h" +#include "cloud_disk_service_manager_mock.h" + +#define stat(path, buf) OHOS::FileManagement::CloudDiskService::Assistant::ins->MockStat(path, buf) +#define access OHOS::FileManagement::CloudDiskService::Assistant::ins->access +#include "cloud_disk_service_logfile.cpp" +#undef stat +#undef access + +namespace OHOS::FileManagement::CloudDiskService::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class CloudDiskServiceLogFileTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr logFile_; + static inline shared_ptr insMock_; +}; + +void CloudDiskServiceLogFileTest::SetUpTestCase(void) { + GTEST_LOG_(INFO) << "SetUpTestCase"; + insMock_ = make_shared(); + Assistant::ins = insMock_; + logFile_ = make_shared(0, 0); +} + +void CloudDiskServiceLogFileTest::TearDownTestCase(void) { + GTEST_LOG_(INFO) << "TearDownTestCase"; + logFile_ = nullptr; + Assistant::ins = nullptr; + insMock_ = nullptr; +} + +void CloudDiskServiceLogFileTest::SetUp() { + +} + +void CloudDiskServiceLogFileTest::TearDown() { + +} + +/** + * @tc.name: WriteLogFileTest001 + * @tc.desc: Verify the WriteLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, WriteLogFileTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WriteLogFileTest001 start"; + try { + LogBlock logBlock; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillOnce(Return(1)); + int32_t res = logFile_->WriteLogFile(logBlock); + EXPECT_EQ(res, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "WriteLogFileTest001 failed"; + } + GTEST_LOG_(INFO) << "WriteLogFileTest001 end"; +} + +/** + * @tc.name: WriteLogFileTest002 + * @tc.desc: Verify the WriteLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, WriteLogFileTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WriteLogFileTest002 start"; + try { + LogBlock logBlock; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).Times(2).WillOnce(Return(0)); + EXPECT_CALL(*insMock_, ReadFile(_, _, _, _)).WillOnce(Return(4096)); + int32_t res = logFile_->WriteLogFile(logBlock); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "WriteLogFileTest002 failed"; + } + GTEST_LOG_(INFO) << "WriteLogFileTest002 end"; +} + +/** + * @tc.name: ReadLogFileTest001 + * @tc.desc: Verify the ReadLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ReadLogFileTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadLogFileTest001 start"; + try { + uint64_t line = 1; + LogBlock logBlock; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillOnce(Return(1)); + int32_t res = logFile_->ReadLogFile(line, logBlock); + EXPECT_EQ(res, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ReadLogFileTest001 failed"; + } + GTEST_LOG_(INFO) << "ReadLogFileTest001 end"; +} + +/** + * @tc.name: ReadLogFileTest002 + * @tc.desc: Verify the ReadLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ReadLogFileTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadLogFileTest002 start"; + try { + uint64_t line = 1; + LogBlock logBlock; + EXPECT_CALL(*insMock_, FilePosLock(_, _, _, _)).WillRepeatedly(Return(0)); + EXPECT_CALL(*insMock_, ReadFile(_, _, _,_)).WillRepeatedly(Return(4096)); + int32_t res = logFile_->ReadLogFile(line, logBlock); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ReadLogFileTest002 failed"; + } + GTEST_LOG_(INFO) << "ReadLogFileTest002 end"; +} + +/** + * @tc.name: OnDataChangeTest001 + * @tc.desc: Verify the OnDataChange function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, OnDataChangeTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnDataChangeTest001 start"; + try { + logFile_->changeDatas_.clear(); + int32_t res = logFile_->OnDataChange(); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "OnDataChangeTest001 failed"; + } + GTEST_LOG_(INFO) << "OnDataChangeTest001 end"; +} + +/** + * @tc.name: OnDataChangeTest002 + * @tc.desc: Verify the OnDataChange function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, OnDataChangeTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnDataChangeTest002 start"; + try { + ChangeData changeData; + logFile_->changeDatas_.push_back(changeData); + int32_t res = logFile_->OnDataChange(); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "OnDataChangeTest002 failed"; + } + GTEST_LOG_(INFO) << "OnDataChangeTest002 end"; +} + +/** + * @tc.name: CloudDiskServiceLogFileTest001 + * @tc.desc: Verify the CloudDiskServiceLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, CloudDiskServiceLogFileTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloudDiskServiceLogFileTest001 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + EXPECT_CALL(*insMock_, access(_, _)).WillOnce(Return(0)); + shared_ptr logFile = + make_shared(userId, syncFolderIndex); + EXPECT_EQ(logFile->userId_, userId); + EXPECT_EQ(logFile->syncFolderIndex_, syncFolderIndex); + EXPECT_FALSE(logFile->needCallback_); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CloudDiskServiceLogFileTest001 failed"; + } + GTEST_LOG_(INFO) << "CloudDiskServiceLogFileTest001 end"; +} + +/** + * @tc.name: CloudDiskServiceLogFileTest002 + * @tc.desc: Verify the CloudDiskServiceLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, CloudDiskServiceLogFileTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloudDiskServiceLogFileTest001 start"; + try { + uint32_t userId = 3; + uint32_t syncFolderIndex = 4; + EXPECT_CALL(*insMock_, access(_, _)).WillOnce(Return(1)); + shared_ptr logFile = + make_shared(userId, syncFolderIndex); + EXPECT_EQ(logFile->userId_, userId); + EXPECT_EQ(logFile->syncFolderIndex_, syncFolderIndex); + EXPECT_FALSE(logFile->needCallback_); + EXPECT_EQ(logFile->currentLine_, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CloudDiskServiceLogFileTest002 failed"; + } + GTEST_LOG_(INFO) << "CloudDiskServiceLogFileTest002 end"; +} + +/** + * @tc.name: GenerateLogBlockTest001 + * @tc.desc: Verify the GenerateLogBlock function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, GenerateLogBlockTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GenerateLogBlockTest001 start"; + try { + EventInfo eventInfo; + uint64_t parentInode = 1; + string childRecordId = "childRecordId"; + string parentRecordId = "parentRecordId"; + uint64_t line = 1; + int32_t res = + logFile_->GenerateLogBlock(eventInfo, parentInode, childRecordId, parentRecordId, line); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GenerateLogBlockTest001 failed"; + } + GTEST_LOG_(INFO) << "GenerateLogBlockTest001 end"; +} + +/** + * @tc.name: GenerateChangeDataTest001 + * @tc.desc: Verify the GenerateChangeData function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, GenerateChangeDataTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GenerateChangeDataTest001 start"; + try { + EventInfo eventInfo; + uint64_t line = 1; + string childRecordId = "childRecordId"; + string parentRecordId = "parentRecordId"; + logFile_->changeDatas_.clear(); + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(1)); + int32_t res = + logFile_->GenerateChangeData(eventInfo, line, childRecordId, parentRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GenerateChangeDataTest001 failed"; + } + GTEST_LOG_(INFO) << "GenerateChangeDataTest001 end"; +} + + +/** + * @tc.name: GenerateChangeDataTest002 + * @tc.desc: Verify the GenerateChangeData function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, GenerateChangeDataTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GenerateChangeDataTest002 start"; + try { + EventInfo eventInfo; + uint64_t line = 1; + string childRecordId = "childRecordId"; + string parentRecordId = "parentRecordId"; + logFile_->changeDatas_.clear(); + for (int i = 0; i < MAX_CHANGEDATAS_SIZE; i++) { + ChangeData changeData; + logFile_->changeDatas_.push_back(changeData); + } + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)); + int32_t res = + logFile_->GenerateChangeData(eventInfo, line, childRecordId, parentRecordId); + EXPECT_EQ(res, E_OK); + EXPECT_TRUE(logFile_->changeDatas_.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GenerateChangeDataTest002 failed"; + } + GTEST_LOG_(INFO) << "GenerateChangeDataTest002 end"; +} + +/** + * @tc.name: FillChildForDirTest001 + * @tc.desc: Verify the FillChildForDir function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, FillChildForDirTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FillChildForDirTest002 start"; + try { + string path = "path"; + uint64_t timestamp = 1; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce([&]() { + errno = ENOENT; + return 1; + }); + int32_t res = + logFile_->FillChildForDir(path, timestamp); + EXPECT_EQ(res, ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FillChildForDirTest001 failed"; + } + GTEST_LOG_(INFO) << "FillChildForDirTest001 end"; +} + +/** + * @tc.name: FillChildForDirTest002 + * @tc.desc: Verify the FillChildForDir function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, FillChildForDirTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FillChildForDirTest002 start"; + try { + string path = "path"; + uint64_t timestamp = 1; + struct stat statInfo; + statInfo.st_mode = S_IFREG; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); + int32_t res = + logFile_->FillChildForDir(path, timestamp); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FillChildForDirTest002 failed"; + } + GTEST_LOG_(INFO) << "FillChildForDirTest002 end"; +} + +/** + * @tc.name: FillChildForDirTest003 + * @tc.desc: Verify the FillChildForDir function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, FillChildForDirTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FillChildForDirTest003 start"; + try { + string path = "path"; + uint64_t timestamp = 1; + struct stat statInfo; + statInfo.st_mode = S_IFDIR; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); + EXPECT_CALL(*insMock_, opendir(_)).WillRepeatedly([&]() { + errno = ENOENT; + return nullptr; + }); + int32_t res = + logFile_->FillChildForDir(path, timestamp); + EXPECT_EQ(res, ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FillChildForDirTest003 failed"; + } + GTEST_LOG_(INFO) << "FillChildForDirTest003 end"; +} + +// /** +// * @tc.name: FillChildForDirTest004 +// * @tc.desc: Verify the FillChildForDir function +// * @tc.type: FUNC +// * @tc.require: NA +// */ +// HWTEST_F(CloudDiskServiceLogFileTest, FillChildForDirTest004, TestSize.Level1) +// { +// GTEST_LOG_(INFO) << "FillChildForDirTest004 start"; +// try { +// string path = "path"; +// uint64_t timestamp = 1; +// struct stat statInfo; +// statInfo.st_mode = S_IFDIR; +// EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); +// DIR* dir = reinterpret_cast(UINT64_MAX); +// EXPECT_CALL(*insMock_, opendir(_)).WillOnce(Return(dir)); +// EXPECT_CALL(*insMock_, readdir(_)).WillOnce(Return(nullptr)); +// int32_t res = +// logFile_->FillChildForDir(path, timestamp); +// EXPECT_EQ(res, E_OK); +// } catch (...) { +// EXPECT_TRUE(false); +// GTEST_LOG_(INFO) << "FillChildForDirTest004 failed"; +// } +// GTEST_LOG_(INFO) << "FillChildForDirTest004 end"; +// } + +// /** +// * @tc.name: FillChildForDirTest005 +// * @tc.desc: Verify the FillChildForDir function +// * @tc.type: FUNC +// * @tc.require: NA +// */ +// HWTEST_F(CloudDiskServiceLogFileTest, FillChildForDirTest005, TestSize.Level1) +// { +// GTEST_LOG_(INFO) << "FillChildForDirTest005 start"; +// try { +// string path = "path"; +// uint64_t timestamp = 1; +// struct stat statInfo; +// statInfo.st_mode = S_IFDIR; +// EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); +// DIR* dir = reinterpret_cast(UINT64_MAX); +// EXPECT_CALL(*insMock_, opendir(_)).WillOnce(Return(dir)); +// dirent *entry1 = new dirent; +// strcpy(entry1->d_name, "."); +// dirent *entry2 = new dirent; +// strcpy(entry2->d_name, ".."); +// dirent *entry = new dirent; +// strcpy(entry->d_name, "name"); +// EXPECT_CALL(*insMock_, readdir(_)).WillOnce(Return(entry1)) +// .WillOnce(Return(entry2)) +// .WillOnce(Return(entry)); +// int32_t res = +// logFile_->FillChildForDir(path, timestamp); +// EXPECT_EQ(res, E_OK); +// } catch (...) { +// EXPECT_TRUE(false); +// GTEST_LOG_(INFO) << "FillChildForDirTest005 failed"; +// } +// GTEST_LOG_(INFO) << "FillChildForDirTest005 end"; +// } + +/** + * @tc.name: StartCallbackTest001 + * @tc.desc: Verify the StartCallback function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, StartCallbackTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StartCallbackTest001 start"; + try { + logFile_->StartCallback(); + EXPECT_TRUE(logFile_->needCallback_); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "StartCallbackTest001 failed"; + } + GTEST_LOG_(INFO) << "StartCallbackTest001 end"; +} + +/** + * @tc.name: StopCallbackTest001 + * @tc.desc: Verify the StopCallback function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, StopCallbackTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StopCallbackTest001 start"; + try { + logFile_->StopCallback(); + EXPECT_FALSE(logFile_->needCallback_); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "StopCallbackTest001 failed"; + } + GTEST_LOG_(INFO) << "StopCallbackTest001 end"; +} + +/** + * @tc.name: ProduceLogTest001 + * @tc.desc: Verify the ProduceLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceLogTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceLogTest001 start"; + try { + EventInfo eventInfo; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce([&]() { + errno = ENOENT; + return 1; + }); + auto res = logFile_->ProduceLog(eventInfo); + EXPECT_EQ(res, ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceLogTest001 failed"; + } + GTEST_LOG_(INFO) << "ProduceLogTest001 end"; +} + +/** + * @tc.name: ProduceLogTest002 + * @tc.desc: Verify the ProduceLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceLogTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceLogTest002 start"; + try { + EventInfo eventInfo; + eventInfo.operateType = static_cast(OperationType::SYNC_FOLDER_INVALID); + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)); + CloudDiskServiceManagerMock& mock = CloudDiskServiceManagerMock::GetInstance(); + EXPECT_CALL(mock, UnregisterForSa(_)).WillOnce(Return(1)); + auto res = logFile_->ProduceLog(eventInfo); + EXPECT_EQ(res, 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceLogTest002 failed"; + } + GTEST_LOG_(INFO) << "ProduceLogTest002 end"; +} + +/** + * @tc.name: ProduceLogTest003 + * @tc.desc: Verify the ProduceLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceLogTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceLogTest003 start"; + try { + EventInfo eventInfo; + eventInfo.operateType = static_cast(OperationType::SYNC_FOLDER_INVALID); + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)); + CloudDiskServiceManagerMock& mock = CloudDiskServiceManagerMock::GetInstance(); + EXPECT_CALL(mock, UnregisterForSa(_)).WillOnce(Return(0)); + auto res = logFile_->ProduceLog(eventInfo); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceLogTest003 failed"; + } + GTEST_LOG_(INFO) << "ProduceLogTest003 end"; +} + +/** + * @tc.name: ProduceLogTest004 + * @tc.desc: Verify the ProduceLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceLogTest004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceLogTest004 start"; + try { + EventInfo eventInfo; + eventInfo.operateType = static_cast(OperationType::OPERATION_MAX); + EXPECT_CALL(*insMock_, MockStat(_, _)).WillRepeatedly(Return(0)); + auto res = logFile_->ProduceLog(eventInfo); + EXPECT_EQ(res, EINVAL); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceLogTest004 failed"; + } + GTEST_LOG_(INFO) << "ProduceLogTest004 end"; +} + +/** + * @tc.name: PraseLogTest001 + * @tc.desc: Verify the PraseLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, PraseLogTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PraseLogTest001 start"; + try { + logFile_->currentLine_ = 1; + uint64_t line = 1; + ChangeData data; + bool isEof = true; + auto res = logFile_->PraseLog(line, data, isEof); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PraseLogTest001 failed"; + } + GTEST_LOG_(INFO) << "PraseLogTest001 end"; +} + +/** + * @tc.name: PraseLogTest002 + * @tc.desc: Verify the PraseLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, PraseLogTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PraseLogTest002 start"; + try { + logFile_->currentLine_ = 0; + uint64_t line = 1; + ChangeData data; + bool isEof = true; + auto res = logFile_->PraseLog(line, data, isEof); + EXPECT_EQ(res, E_INVALID_CHANGE_SEQUENCE); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PraseLogTest002 failed"; + } + GTEST_LOG_(INFO) << "PraseLogTest002 end"; +} + +/** + * @tc.name: PraseLogTest003 + * @tc.desc: Verify the PraseLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, PraseLogTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PraseLogTest003 start"; + try { + logFile_->userId_ = 1; + logFile_->currentLine_ = 1; + uint64_t line = 1; + ChangeData data; + bool isEof = true; + auto res = logFile_->PraseLog(line, data, isEof); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PraseLogTest003 failed"; + } + GTEST_LOG_(INFO) << "PraseLogTest003 end"; +} + +/** + * @tc.name: ProductLogForOperateTest001 + * @tc.desc: Verify the ProductLogForOperate function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProductLogForOperateTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProductLogForOperateTest001 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + uint8_t operator1 = static_cast(OperationType::CREATE); + logFile_->ProductLogForOperate(parentMetaFile, path, name, childRecordId, operator1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProductLogForOperateTest001 failed"; + } + GTEST_LOG_(INFO) << "ProductLogForOperateTest001 end"; +} + +/** + * @tc.name: ProductLogForOperateTest002 + * @tc.desc: Verify the ProductLogForOperate function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProductLogForOperateTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProductLogForOperateTest002 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + uint8_t operator1 = static_cast(OperationType::DELETE); + logFile_->ProductLogForOperate(parentMetaFile, path, name, childRecordId, operator1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProductLogForOperateTest002 failed"; + } + GTEST_LOG_(INFO) << "ProductLogForOperateTest002 end"; +} + +/** + * @tc.name: ProductLogForOperateTest003 + * @tc.desc: Verify the ProductLogForOperate function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProductLogForOperateTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProductLogForOperateTest003 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + uint8_t operator1 = static_cast(OperationType::MOVE_FROM); + logFile_->ProductLogForOperate(parentMetaFile, path, name, childRecordId, operator1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProductLogForOperateTest003 failed"; + } + GTEST_LOG_(INFO) << "ProductLogForOperateTest003 end"; +} + +/** + * @tc.name: ProductLogForOperateTest004 + * @tc.desc: Verify the ProductLogForOperate function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProductLogForOperateTest004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProductLogForOperateTest004 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + uint8_t operator1 = static_cast(OperationType::MOVE_TO); + logFile_->ProductLogForOperate(parentMetaFile, path, name, childRecordId, operator1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProductLogForOperateTest004 failed"; + } + GTEST_LOG_(INFO) << "ProductLogForOperateTest004 end"; +} + +/** + * @tc.name: ProductLogForOperateTest005 + * @tc.desc: Verify the ProductLogForOperate function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProductLogForOperateTest005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProductLogForOperateTest005 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + uint8_t operator1 = static_cast(OperationType::CLOSE_WRITE); + logFile_->ProductLogForOperate(parentMetaFile, path, name, childRecordId, operator1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProductLogForOperateTest005 failed"; + } + GTEST_LOG_(INFO) << "ProductLogForOperateTest005 end"; +} + +/** + * @tc.name: ProductLogForOperateTest006 + * @tc.desc: Verify the ProductLogForOperate function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProductLogForOperateTest006, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProductLogForOperateTest006 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + uint8_t operator1 = static_cast(OperationType::SYNC_FOLDER_INVALID); + logFile_->ProductLogForOperate(parentMetaFile, path, name, childRecordId, operator1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProductLogForOperateTest006 failed"; + } + GTEST_LOG_(INFO) << "ProductLogForOperateTest006 end"; +} + +/** + * @tc.name: ProductLogForOperateTest007 + * @tc.desc: Verify the ProductLogForOperate function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProductLogForOperateTest007, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProductLogForOperateTest007 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + uint8_t operator1 = static_cast(OperationType::OPERATION_MAX); + logFile_->ProductLogForOperate(parentMetaFile, path, name, childRecordId, operator1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProductLogForOperateTest007 failed"; + } + GTEST_LOG_(INFO) << "ProductLogForOperateTest007 end"; +} + +/** + * @tc.name: ProduceCreateLogTest001 + * @tc.desc: Verify the ProduceCreateLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceCreateLogTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceCreateLogTest001 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce([&]() { + errno = ENOENT; + return 1; + }); + auto res = logFile_->ProduceCreateLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceCreateLogTest001 failed"; + } + GTEST_LOG_(INFO) << "ProduceCreateLogTest001 end"; +} + +/** + * @tc.name: ProduceCreateLogTest002 + * @tc.desc: Verify the ProduceCreateLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceCreateLogTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceCreateLogTest002 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)); + auto res = logFile_->ProduceCreateLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceCreateLogTest002 failed"; + } + GTEST_LOG_(INFO) << "ProduceCreateLogTest002 end"; +} + +/** + * @tc.name: ProduceCreateLogTest003 + * @tc.desc: Verify the ProduceCreateLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceCreateLogTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceCreateLogTest003 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = ""; + string childRecordId = "childRecordId"; + struct stat statInfo; + statInfo.st_ino = S_IFREG; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); + auto res = logFile_->ProduceCreateLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceCreateLogTest003 failed"; + } + GTEST_LOG_(INFO) << "ProduceCreateLogTest003 end"; +} + +/** + * @tc.name: ProduceCreateLogTest004 + * @tc.desc: Verify the ProduceCreateLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceCreateLogTest004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceCreateLogTest004 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = ""; + string childRecordId = "childRecordId"; + struct stat statInfo; + statInfo.st_ino = S_IFDIR; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); + auto res = logFile_->ProduceCreateLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceCreateLogTest004 failed"; + } + GTEST_LOG_(INFO) << "ProduceCreateLogTest004 end"; +} + +/** + * @tc.name: ProduceUnlinkLogTest001 + * @tc.desc: Verify the ProduceUnlinkLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceUnlinkLogTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceUnlinkLogTest001 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string name = "name"; + string childRecordId = "childRecordId"; + auto res = logFile_->ProduceUnlinkLog(parentMetaFile, name, childRecordId); + EXPECT_EQ(res, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceUnlinkLogTest001 failed"; + } + GTEST_LOG_(INFO) << "ProduceUnlinkLogTest001 end"; +} + +/** + * @tc.name: ProduceUnlinkLogTest002 + * @tc.desc: Verify the ProduceUnlinkLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceUnlinkLogTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceUnlinkLogTest001 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string name = "name"; + string childRecordId = ""; + auto res = logFile_->ProduceUnlinkLog(parentMetaFile, name, childRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceUnlinkLogTest002 failed"; + } + GTEST_LOG_(INFO) << "ProduceUnlinkLogTest002 end"; +} + +/** + * @tc.name: ProduceRenameOldLogTest001 + * @tc.desc: Verify the ProduceRenameOldLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceRenameOldLogTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceRenameOldLogTest001 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string name = "name"; + string childRecordId = "childRecordId"; + auto res = logFile_->ProduceRenameOldLog(parentMetaFile, name, childRecordId); + EXPECT_EQ(res, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceRenameOldLogTest001 failed"; + } + GTEST_LOG_(INFO) << "ProduceRenameOldLogTest001 end"; +} + +/** + * @tc.name: ProduceRenameOldLogTest002 + * @tc.desc: Verify the ProduceRenameOldLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceRenameOldLogTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceRenameOldLogTest002 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string name = "name"; + string childRecordId = ""; + auto res = logFile_->ProduceRenameOldLog(parentMetaFile, name, childRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceRenameOldLogTest002 failed"; + } + GTEST_LOG_(INFO) << "ProduceRenameOldLogTest002 end"; +} + +/** + * @tc.name: ProduceRenameNewLogTest001 + * @tc.desc: Verify the ProduceRenameNewLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceRenameNewLogTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest001 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce([&]() { + errno = ENOENT; + return 1; + }); + auto res = logFile_->ProduceRenameNewLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest001 failed"; + } + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest001 end"; +} + +/** + * @tc.name: ProduceRenameNewLogTest002 + * @tc.desc: Verify the ProduceRenameNewLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceRenameNewLogTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest002 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + logFile_->renameRecordId_ = "renameRecordId"; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)); + auto res = logFile_->ProduceRenameNewLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest002 failed"; + } + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest002 end"; +} + +/** + * @tc.name: ProduceRenameNewLogTest003 + * @tc.desc: Verify the ProduceRenameNewLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceRenameNewLogTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest003 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = ""; + logFile_->renameRecordId_ = ""; + struct stat statInfo; + statInfo.st_ino = S_IFREG; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); + auto res = logFile_->ProduceRenameNewLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest003 failed"; + } + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest003 end"; +} + +/** + * @tc.name: ProduceRenameNewLogTest004 + * @tc.desc: Verify the ProduceRenameNewLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceRenameNewLogTest004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest004 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = ""; + struct stat statInfo; + statInfo.st_ino = S_IFDIR; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(DoAll(SetArgPointee<1>(statInfo), Return(0))); + auto res = logFile_->ProduceRenameNewLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest004 failed"; + } + GTEST_LOG_(INFO) << "ProduceRenameNewLogTest004 end"; +} + +/** + * @tc.name: ProduceCloseAndWriteLogTest001 + * @tc.desc: Verify the ProduceCloseAndWriteLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceCloseAndWriteLogTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest001 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce([&]() { + errno = ENOENT; + return 1; + }); + auto res = logFile_->ProduceCloseAndWriteLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest001 failed"; + } + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest001 end"; +} + +/** + * @tc.name: ProduceCloseAndWriteLogTest002 + * @tc.desc: Verify the ProduceCloseAndWriteLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceCloseAndWriteLogTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest002 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = "childRecordId"; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)); + auto res = logFile_->ProduceCloseAndWriteLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest002 failed"; + } + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest002 end"; +} + +/** + * @tc.name: ProduceCloseAndWriteLogTest003 + * @tc.desc: Verify the ProduceCloseAndWriteLog function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceLogFileTest, ProduceCloseAndWriteLogTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest003 start"; + try { + shared_ptr parentMetaFile = + make_shared(0, 0, 0); + string path = "path"; + string name = "name"; + string childRecordId = ""; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)); + auto res = logFile_->ProduceCloseAndWriteLog(parentMetaFile, path, name, childRecordId); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest003 failed"; + } + GTEST_LOG_(INFO) << "ProduceCloseAndWriteLogTest003 end"; +} + +class LogFileMgrTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr logFileMgr_; + static inline shared_ptr insMock_; +}; + +void LogFileMgrTest::SetUpTestCase(void) { + GTEST_LOG_(INFO) << "SetUpTestCase"; + insMock_ = make_shared(); + Assistant::ins = insMock_; + logFileMgr_ = make_shared(); +} + +void LogFileMgrTest::TearDownTestCase(void) { + GTEST_LOG_(INFO) << "TearDownTestCase"; + logFileMgr_ = nullptr; + Assistant::ins = nullptr; + insMock_ = nullptr; +} + +void LogFileMgrTest::SetUp() { + +} + +void LogFileMgrTest::TearDown() { + +} + +/** + * @tc.name: GetInstanceTest001 + * @tc.desc: Verify the GetInstance function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, GetInstanceTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetInstanceTest001 start"; + try { + LogFileMgr& instance1 = LogFileMgr::GetInstance(); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetInstanceTest001 failed"; + } + GTEST_LOG_(INFO) << "GetInstanceTest001 end"; +} + +/** + * @tc.name: ProduceRequestTest001 + * @tc.desc: Verify the ProduceRequest function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, ProduceRequestTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ProduceRequestTest001 start"; + try { + EventInfo eventInfo; + auto res = logFileMgr_->ProduceRequest(eventInfo); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ProduceRequestTest001 failed"; + } + GTEST_LOG_(INFO) << "ProduceRequestTest001 end"; +} + +/** + * @tc.name: PraseRequestTest001 + * @tc.desc: Verify the PraseRequest function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, PraseRequestTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PraseRequestTest001 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 1; + uint64_t start = 1; + uint64_t count = 1; + ChangesResult changeResult; + logFileMgr_->PraseRequest(userId, syncFolderIndex, start, count, changeResult); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "PraseRequestTest001 failed"; + } + GTEST_LOG_(INFO) << "PraseRequestTest001 end"; +} + +/** + * @tc.name: RegisterSyncFolderTest001 + * @tc.desc: Verify the RegisterSyncFolder function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, RegisterSyncFolderTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterSyncFolderTest001 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + string path = "path"; + EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce([&]() { + errno = ENOENT; + return 1; + }); + auto res = logFileMgr_->RegisterSyncFolder(userId, syncFolderIndex, path); + EXPECT_EQ(res, ENOENT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RegisterSyncFolderTest001 failed"; + } + GTEST_LOG_(INFO) << "RegisterSyncFolderTest001 end"; +} + +// /** +// * @tc.name: RegisterSyncFolderTest002 +// * @tc.desc: Verify the RegisterSyncFolder function +// * @tc.type: FUNC +// * @tc.require: NA +// */ +// HWTEST_F(LogFileMgrTest, RegisterSyncFolderTest002, TestSize.Level1) +// { +// GTEST_LOG_(INFO) << "RegisterSyncFolderTest002 start"; +// try { +// uint32_t userId = 1; +// uint32_t syncFolderIndex = 2; +// string path = "path"; +// EXPECT_CALL(*insMock_, MockStat(_, _)).WillOnce(Return(0)) +// .WillOnce(Return(1)); +// auto res = logFileMgr_->RegisterSyncFolder(userId, syncFolderIndex, path); +// EXPECT_EQ(res, E_OK); +// } catch (...) { +// EXPECT_TRUE(false); +// GTEST_LOG_(INFO) << "RegisterSyncFolderTest002 failed"; +// } +// GTEST_LOG_(INFO) << "RegisterSyncFolderTest002 end"; +// } + +/** + * @tc.name: UnRegisterSyncFolderTest001 + * @tc.desc: Verify the UnRegisterSyncFolder function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, UnRegisterSyncFolderTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnRegisterSyncFolderTest001 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + auto res = logFileMgr_->UnRegisterSyncFolder(userId, syncFolderIndex); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "UnRegisterSyncFolderTest001 failed"; + } + GTEST_LOG_(INFO) << "UnRegisterSyncFolderTest001 end"; +} + +/** + * @tc.name: RegisterSyncFolderChangesTest001 + * @tc.desc: Verify the RegisterSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, RegisterSyncFolderChangesTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest001 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + logFileMgr_->registerChangeCount_ = 0; + logFileMgr_->RegisterSyncFolderChanges(userId, syncFolderIndex); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest001 failed"; + } + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest001 end"; +} + +/** + * @tc.name: RegisterSyncFolderChangesTest002 + * @tc.desc: Verify the RegisterSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, RegisterSyncFolderChangesTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest002 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + logFileMgr_->registerChangeCount_ = 1; + logFileMgr_->RegisterSyncFolderChanges(userId, syncFolderIndex); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest002 failed"; + } + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest002 end"; +} + +/** + * @tc.name: UnRegisterSyncFolderChangesTest001 + * @tc.desc: Verify the UnRegisterSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, UnRegisterSyncFolderChangesTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest001 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + logFileMgr_->registerChangeCount_ = 1; + logFileMgr_->UnRegisterSyncFolderChanges(userId, syncFolderIndex); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest001 failed"; + } + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest001 end"; +} + +/** + * @tc.name: UnRegisterSyncFolderChangesTest002 + * @tc.desc: Verify the UnRegisterSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, UnRegisterSyncFolderChangesTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest002 start"; + try { + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + logFileMgr_->registerChangeCount_ = 2; + logFileMgr_->UnRegisterSyncFolderChanges(userId, syncFolderIndex); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest002 failed"; + } + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest002 end"; +} + +/** + * @tc.name: GetCloudDiskServiceLogFileTest001 + * @tc.desc: Verify the GetCloudDiskServiceLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, GetCloudDiskServiceLogFileTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetCloudDiskServiceLogFileTest001 start"; + try { + logFileMgr_->LogFiles_.clear(); + uint32_t userId = 1; + uint32_t syncFolderIndex = 2; + auto res = logFileMgr_->GetCloudDiskServiceLogFile(userId, syncFolderIndex); + EXPECT_EQ(res->userId_, userId); + EXPECT_EQ(res->syncFolderIndex_, syncFolderIndex); + EXPECT_FALSE(logFileMgr_->LogFiles_.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetCloudDiskServiceLogFileTest001 failed"; + } + GTEST_LOG_(INFO) << "GetCloudDiskServiceLogFileTest001 end"; +} + +/** + * @tc.name: GetCloudDiskServiceLogFileTest002 + * @tc.desc: Verify the GetCloudDiskServiceLogFile function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, GetCloudDiskServiceLogFileTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetCloudDiskServiceLogFileTest002 start"; + try { + logFileMgr_->LogFiles_.clear(); + uint32_t userId = 3; + uint32_t syncFolderIndex = 4; + LogFileKey key(userId, syncFolderIndex); + shared_ptr newLogFile = make_shared(0, 0); + logFileMgr_->LogFiles_[key] = newLogFile; + auto res = logFileMgr_->GetCloudDiskServiceLogFile(userId, syncFolderIndex); + EXPECT_EQ(res, newLogFile); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetCloudDiskServiceLogFileTest002 failed"; + } + GTEST_LOG_(INFO) << "GetCloudDiskServiceLogFileTest002 end"; +} + +/** + * @tc.name: CallBackTest001 + * @tc.desc: Verify the CallBack function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, CallBackTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CallBackTest001 start"; + try { + logFileMgr_->CallBack(nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "CallBackTest001 failed"; + } + GTEST_LOG_(INFO) << "CallBackTest001 end"; +} + +/** + * @tc.name: OnDataChangeTest001 + * @tc.desc: Verify the OnDataChange function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(LogFileMgrTest, OnDataChangeTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnDataChangeTest001 start"; + try { + auto res = logFileMgr_->OnDataChange(); + EXPECT_EQ(res, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "OnDataChangeTest001 failed"; + } + GTEST_LOG_(INFO) << "OnDataChangeTest001 end"; +} +} \ No newline at end of file diff --git a/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_metafile_test.cpp b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_metafile_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..598b44369ffd1d3a8f92ccfe0ef6c1fa63bbd1e5 --- /dev/null +++ b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_metafile_test.cpp @@ -0,0 +1,565 @@ +/* + * 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 + +#include "assistant.h" +#include "dfs_error.h" + +#include "cloud_disk_service_metafile.cpp" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; +using namespace testing; +using namespace testing::ext; + +class CloudDiskServiceMetafileTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr insMock; +}; + +void CloudDiskServiceMetafileTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void CloudDiskServiceMetafileTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void CloudDiskServiceMetafileTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; + insMock = make_shared(); + Assistant::ins = insMock; +} + +void CloudDiskServiceMetafileTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; + Assistant::ins = nullptr; + insMock = nullptr; +} + +/** + * @tc.name: GetBucketByLevelTest001 + * @tc.desc: Verify the GetBucketByLevel function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetOverallBucketTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetOverallBucketTest001 Start"; + try { + uint32_t level = MAX_BUCKET_LEVEL + 1; + uint32_t ret = GetOverallBucket(level); + EXPECT_EQ(ret, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetOverallBucketTest001 ERROR"; + } + GTEST_LOG_(INFO) << "GetOverallBucketTest001 End"; +} + +/** + * @tc.name: GetOverallBucketTest002 + * @tc.desc: Verify the GetOverallBucket function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetOverallBucketTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetOverallBucketTest002 Start"; + try { + uint32_t level = 1; + uint32_t ret = GetOverallBucket(level); + EXPECT_EQ(ret, static_cast((1ULL << (level + 1))) - 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetOverallBucketTest002 ERROR"; + } + GTEST_LOG_(INFO) << "GGetOverallBucketTest002 End"; +} + +/** + * @tc.name: GetDcacheFileSizeTest001 + * @tc.desc: Verify the GetDcacheFileSize function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetDcacheFileSizeTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDcacheFileSizeTest001 Start"; + try { + uint32_t level = 1; + size_t buckets = GetOverallBucket(level); + size_t ret = GetDcacheFileSize(level); + EXPECT_EQ(ret, buckets * DENTRYGROUP_SIZE * BUCKET_BLOCKS + DENTRYGROUP_HEADER); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetDcacheFileSizeTest001 ERROR"; + } + GTEST_LOG_(INFO) << "GetDcacheFileSizeTest001 End"; +} + +/** + * @tc.name: GetBucketByLevelTest001 + * @tc.desc: Verify the GetBucketByLevel function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetBucketByLevelTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBucketByLevelTest001 Start"; + try { + uint32_t level = MAX_BUCKET_LEVEL + 1; + uint32_t ret = GetBucketByLevel(level); + EXPECT_EQ(ret, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBucketByLevelTest001 ERROR"; + } + GTEST_LOG_(INFO) << "GetBucketByLevelTest001 End"; +} + +/** + * @tc.name: GetBucketByLevelTest002 + * @tc.desc: Verify the GetBucketByLevel function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetBucketByLevelTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBucketByLevelTest002 Start"; + try { + uint32_t level = 1; + uint32_t ret = GetBucketByLevel(level); + EXPECT_EQ(ret, static_cast((1ULL << level))); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBucketByLevelTest002 ERROR"; + } + GTEST_LOG_(INFO) << "GetBucketByLevelTest002 End"; +} + +/** + * @tc.name: GetBucketaddrTest001 + * @tc.desc: Verify the GetBucketaddr function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetBucketaddrTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBucketaddrTest001 Start"; + try { + uint32_t level = MAX_BUCKET_LEVEL + 1; + uint32_t buckoffset = 0; + uint32_t ret = GetBucketaddr(level, buckoffset); + EXPECT_EQ(ret, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBucketaddrTest001 ERROR"; + } + GTEST_LOG_(INFO) << "GetBucketaddrTest001 End"; +} + +/** + * @tc.name: GetBucketaddrTest002 + * @tc.desc: Verify the GetBucketaddr function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetBucketaddrTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBucketaddrTest002 Start"; + try { + uint32_t level = 1; + uint64_t curLevelMaxBucks = (1ULL << level); + uint32_t buckoffset = curLevelMaxBucks + 1; + uint32_t ret = GetBucketaddr(level, buckoffset); + EXPECT_EQ(ret, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBucketaddrTest002 ERROR"; + } + GTEST_LOG_(INFO) << "GetBucketaddrTest002 End"; +} + +/** + * @tc.name: GetBucketaddrTest003 + * @tc.desc: Verify the GetBucketaddr function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetBucketaddrTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBucketaddrTest003 Start"; + try { + uint32_t level = 1; + uint64_t curLevelMaxBucks = (1ULL << level); + uint32_t buckoffset = curLevelMaxBucks - 1; + uint32_t ret = GetBucketaddr(level, buckoffset); + EXPECT_EQ(ret, static_cast(curLevelMaxBucks) + buckoffset - 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBucketaddrTest003 ERROR"; + } + GTEST_LOG_(INFO) << "GetBucketaddrTest003 End"; +} + +/** + * @tc.name: GetBidxFromLevelTest001 + * @tc.desc: Verify the GetBidxFromLevel function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetBidxFromLevelTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBidxFromLevelTest001 Start"; + try { + uint32_t level = MAX_BUCKET_LEVEL + 1; + uint32_t namehash = 1; + unsigned long ret = GetBidxFromLevel(level, namehash); + EXPECT_EQ(ret, E_OK); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBidxFromLevelTest001 ERROR"; + } + GTEST_LOG_(INFO) << "GetBidxFromLevelTest001 End"; +} + +/** + * @tc.name: GetBidxFromLevelTest002 + * @tc.desc: Verify the GetBidxFromLevel function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetBidxFromLevelTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBidxFromLevelTest002 Start"; + try { + uint32_t level = 1; + uint32_t namehash = 1; + uint32_t bucket = GetBucketByLevel(level); + unsigned long ret = GetBidxFromLevel(level, namehash); + EXPECT_EQ(ret, BUCKET_BLOCKS * GetBucketaddr(level, namehash % bucket)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetBidxFromLevelTest002 ERROR"; + } + GTEST_LOG_(INFO) << "GetBidxFromLevelTest002 End"; +} + +/** + * @tc.name: FindDentryPageTest001 + * @tc.desc: Verify the FindDentryPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, FindDentryPageTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FindDentryPageTest001 Start"; + try { + uint64_t index = 0; + auto ctx = std::make_shared(); + auto dentryBlk = std::make_unique(); + EXPECT_CALL(*insMock, FilePosLock(_, _, _, _)).WillOnce(Return(1)); + auto ret = FindDentryPage(index, ctx.get()); + EXPECT_EQ(ret, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FindDentryPageTest001 ERROR"; + } + GTEST_LOG_(INFO) << "FindDentryPageTest001 End"; +} + +/** + * @tc.name: FindDentryPageTest002 + * @tc.desc: Verify the FindDentryPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, FindDentryPageTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FindDentryPageTest002 Start"; + try { + uint64_t index = 1; + auto ctx = std::make_shared(); + auto dentryBlk = std::make_unique(); + EXPECT_CALL(*insMock, FilePosLock(_, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*insMock, ReadFile(_, _, _, _)).WillOnce(Return(DENTRYGROUP_SIZE)); + auto ret = FindDentryPage(index, ctx.get()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FindDentryPageTest002 ERROR"; + } + GTEST_LOG_(INFO) << "FindDentryPageTest002 End"; +} + +/** + * @tc.name: FindDentryPageTest003 + * @tc.desc: Verify the FindDentryPage function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, FindDentryPageTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FindDentryPageTest003 Start"; + try { + uint64_t index = 1; + auto ctx = std::make_shared(); + auto dentryBlk = std::make_unique(); + EXPECT_CALL(*insMock, FilePosLock(_, _, _, _)).Times(2).WillRepeatedly(Return(0)); + EXPECT_CALL(*insMock, ReadFile(_, _, _, _)).WillOnce(Return(1)); + auto ret = FindDentryPage(index, ctx.get()); + EXPECT_EQ(ret, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FindDentryPageTest003 ERROR"; + } + GTEST_LOG_(INFO) << "FindDentryPageTest003 End"; +} + +/** + * @tc.name: FindInBlockByIdTest001 + * @tc.desc: Verify the FindInBlockById function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, FindInBlockByIdTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FindInBlockByIdTest001 Start"; + try { + CloudDiskServiceDentryGroup dentryBlk; + uint32_t namehash = 0; + std::string recordId = "test"; + uint8_t revalidate = 0; + auto ret = FindInBlockById(dentryBlk, namehash, recordId, revalidate); + EXPECT_EQ(ret, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FindInBlockByIdTest001 ERROR"; + } + GTEST_LOG_(INFO) << "FindInBlockByIdTest001 End"; +} + +/** + * @tc.name: FindInBlockTest001 + * @tc.desc: Verify the FindInBlock function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, FindInBlockTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FindInBlockIdTest001 Start"; + try { + CloudDiskServiceDentryGroup dentryBlk; + uint32_t namehash = 0; + std::string name = "testName"; + uint8_t revalidate = 0; + auto ret = FindInBlock(dentryBlk, namehash, name, revalidate); + EXPECT_EQ(ret, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FindInBlockTest001 ERROR"; + } + GTEST_LOG_(INFO) << "FindInBlockTest001 End"; +} + +/** + * @tc.name: InLevelTest001 + * @tc.desc: Verify the InLevel function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, InLevelTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "InLevelTest001 Start"; + try { + uint32_t level = MAX_BUCKET_LEVEL + 1; + DcacheLookupCtx *ctx = nullptr; + bool byId = true; + uint8_t revalidate = 0; + auto ret = InLevel(level, ctx, byId, revalidate); + EXPECT_EQ(ret, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "InLevelTest001 ERROR"; + } + GTEST_LOG_(INFO) << "InLevelTest001 End"; +} + +/** + * @tc.name: InLevelTest002 + * @tc.desc: Verify the InLevel function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, InLevelTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "InLevelTest002 Start"; + try { + uint32_t level = 1; + shared_ptr ctx = make_shared(); + bool byId = true; + uint8_t revalidate = 0; + EXPECT_CALL(*insMock, FilePosLock(_, _, _, _)).Times(2).WillRepeatedly(Return(0)); + EXPECT_CALL(*insMock, ReadFile(_, _, _, _)).WillOnce(Return(1)); + auto ret = InLevel(level, ctx.get(), byId, revalidate); + EXPECT_EQ(ret, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "InLevelTest002 ERROR"; + } + GTEST_LOG_(INFO) << "InLevelTest002 End"; +} + +/** + * @tc.name: FindDentryTest001 + * @tc.desc: Verify the FindDentry function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, FindDentryTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FindDentryTest001 Start"; + try { + shared_ptr ctx = make_shared(); + FindDentry(ctx.get()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "FindDentryTest002 ERROR"; + } + GTEST_LOG_(INFO) << "FindDentryTest002 End"; +} + +/** + * @tc.name: InitDcacheLookupCtxTest001 + * @tc.desc: Verify the InitDcacheLookupCtx function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, InitDcacheLookupCtxTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "InitDcacheLookupCtxTest001 Start"; + try { + shared_ptr ctx = make_shared(); + MetaBase base; + base.name = "MetaBase_name"; + InitDcacheLookupCtx(ctx.get(), base, 0, 0); + EXPECT_EQ(ctx->fd, 0); + EXPECT_EQ(ctx->name, base.name); + EXPECT_EQ(ctx->bidx, 0); + EXPECT_EQ(ctx->page, nullptr); + EXPECT_EQ(ctx->hash, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "InitDcacheLookupCtxTest001 ERROR"; + } + GTEST_LOG_(INFO) << "InitDcacheLookupCtxTest001 End"; +} + +/** + * @tc.name: RoomForFilenameTest001 + * @tc.desc: Verify the RoomForFilename function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, RoomForFilenameTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RoomForFilenameTest001 Start"; + try { + size_t slots = 2; + uint32_t maxSlots = 5; + uint8_t bitmap[] = {1, 1, 1, 1, 1}; + uint32_t ret = RoomForFilename(bitmap, slots, maxSlots); + EXPECT_EQ(ret, 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RoomForFilenameTest001 ERROR"; + } + GTEST_LOG_(INFO) << "RoomForFilenameTest001 End"; +} + +/** + * @tc.name: RoomForFilenameTest002 + * @tc.desc: Verify the RoomForFilename function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, RoomForFilenameTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RoomForFilenameTest002 Start"; + try { + size_t slots = 2; + uint32_t maxSlots = 5; + uint8_t bitmap[] = {0, 0, 0, 0, 0}; + uint32_t ret = RoomForFilename(bitmap, slots, maxSlots); + EXPECT_EQ(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RoomForFilenameTest002 ERROR"; + } + GTEST_LOG_(INFO) << "RoomForFilenameTest002 End"; +} + +/** + * @tc.name: RoomForFilenameTest003 + * @tc.desc: Verify the RoomForFilename function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, RoomForFilenameTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RoomForFilenameTest003 Start"; + try { + size_t slots = 2; + uint32_t maxSlots = 5; + uint8_t bitmap[] = {1, 1, 1, 1, 0}; + uint32_t ret = RoomForFilename(bitmap, slots, maxSlots); + EXPECT_EQ(ret, 1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RoomForFilenameTest003 ERROR"; + } + GTEST_LOG_(INFO) << "RoomForFilenameTest003 End"; +} + +/** + * @tc.name: GetDentryFileByPathTest001 + * @tc.desc: Verify the GetDentryFileByPath function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceMetafileTest, GetDentryFileByPathTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDentryFileByPathTest001 Start"; + try { + uint32_t userId = 100; + std::string index = "index"; + std::string inode = "inode"; + GetDentryFileByPath(userId, index, inode); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetDentryFileByPathTest001 ERROR"; + } + GTEST_LOG_(INFO) << "GetDentryFileByPathTest001 End"; +} +} // namespace OHOS::FileManagement::CloudDiskService diff --git a/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_syncfolder_test.cpp b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_syncfolder_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a6a8f60c95f0b1749a64c1727bf1a119990f5997 --- /dev/null +++ b/test/unittests/clouddiskservice/sync_folder/cloud_disk_service_syncfolder_test.cpp @@ -0,0 +1,171 @@ +/* + * 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 "cloud_disk_service_syncfolder.cpp" + +#include +#include + +namespace OHOS::FileManagement::CloudDiskService::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class CloudDiskServiceSyncFolderTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void CloudDiskServiceSyncFolderTest::SetUpTestCase(void) { + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void CloudDiskServiceSyncFolderTest::TearDownTestCase(void) { + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void CloudDiskServiceSyncFolderTest::SetUp() { + +} + +void CloudDiskServiceSyncFolderTest::TearDown() { + +} + +/** + * @tc.name: RegisterSyncFolderTest001 + * @tc.desc: Verify the RegisterSyncFolder function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceSyncFolderTest, RegisterSyncFolderTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterSyncFolderTest001 start"; + try { + int32_t userId = 1; + uint64_t syncFolderIndex = 1; + string path = "path"; + CloudDiskServiceSyncFolder::RegisterSyncFolder(userId, syncFolderIndex, path); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RegisterSyncFolderTest001 failed"; + } + GTEST_LOG_(INFO) << "RegisterSyncFolderTest001 end"; +} + +/** + * @tc.name: UnRegisterSyncFolderTest001 + * @tc.desc: Verify the UnRegisterSyncFolder function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceSyncFolderTest, UnRegisterSyncFolderTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnRegisterSyncFolderTest001 start"; + try { + int32_t userId = 1; + uint64_t syncFolderIndex = 1; + CloudDiskServiceSyncFolder::UnRegisterSyncFolder(userId, syncFolderIndex); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "UnRegisterSyncFolderTest001 failed"; + } + GTEST_LOG_(INFO) << "UnRegisterSyncFolderTest001 end"; +} + +/** + * @tc.name: RegisterSyncFolderChangesTest001 + * @tc.desc: Verify the RegisterSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceSyncFolderTest, RegisterSyncFolderChangesTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest001 start"; + try { + int32_t userId = 1; + uint64_t syncFolderIndex = 1; + CloudDiskServiceSyncFolder::RegisterSyncFolderChanges(userId, syncFolderIndex); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest001 failed"; + } + GTEST_LOG_(INFO) << "RegisterSyncFolderChangesTest001 end"; +} + +/** + * @tc.name: UnRegisterSyncFolderChangesTest001 + * @tc.desc: Verify the RegisterSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceSyncFolderTest, UnRegisterSyncFolderChangesTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest001 start"; + try { + int32_t userId = 1; + uint64_t syncFolderIndex = 1; + CloudDiskServiceSyncFolder::UnRegisterSyncFolderChanges(userId, syncFolderIndex); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest001 failed"; + } + GTEST_LOG_(INFO) << "UnRegisterSyncFolderChangesTest001 end"; +} + +/** + * @tc.name: GetSyncFolderChangesTest001 + * @tc.desc: Verify the GetSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceSyncFolderTest, GetSyncFolderChangesTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetSyncFolderChangesTest001 start"; + try { + int32_t userId = 1; + uint64_t syncFolderIndex = 1; + uint64_t start = 1; + uint64_t count = 1; + ChangesResult changesResult; + CloudDiskServiceSyncFolder::GetSyncFolderChanges(userId, syncFolderIndex, start, count, changesResult); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GetSyncFolderChangesTest001 failed"; + } + GTEST_LOG_(INFO) << "GetSyncFolderChangesTest001 end"; +} + +/** + * @tc.name: SetSyncFolderChangesTest001 + * @tc.desc: Verify the SetSyncFolderChanges function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(CloudDiskServiceSyncFolderTest, SetSyncFolderChangesTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SetSyncFolderChangesTest001 start"; + try { + EventInfo eventInfo; + CloudDiskServiceSyncFolder::SetSyncFolderChanges(eventInfo); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "SetSyncFolderChangesTest001 failed"; + } + GTEST_LOG_(INFO) << "SetSyncFolderChangesTest001 end"; +} +} \ No newline at end of file diff --git a/test/unittests/clouddiskservice/sync_folder/convertor_test.cpp b/test/unittests/clouddiskservice/sync_folder/convertor_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd3140e76329039106c7c9e8e9e63b0199145817 --- /dev/null +++ b/test/unittests/clouddiskservice/sync_folder/convertor_test.cpp @@ -0,0 +1,101 @@ +/* + * 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 +#include + +#include "convertor.h" +#include "utils_log.h" + +namespace OHOS { +namespace FileManagement::CloudDiskService { +namespace Test { +using namespace testing::ext; +using namespace std; + +class ConvertorTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ConvertorTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void ConvertorTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void ConvertorTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void ConvertorTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: ConvertToHexTest001 + * @tc.desc: Verify the ConvertToHex function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(ConvertorTest, ConvertToHexTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ConvertToHexTest001 start"; + try { + EXPECT_EQ(Convertor::ConvertToHex(0), "0000000000000000"); + EXPECT_EQ(Convertor::ConvertToHex(1), "0000000000000001"); + EXPECT_EQ(Convertor::ConvertToHex(255), "00000000000000ff"); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ConvertToHexTest001 failed"; + } + GTEST_LOG_(INFO) << "ConvertToHexTest001 end"; +} + +/** + * @tc.name: ConvertFromHexTest001 + * @tc.desc: Verify the ConvertFromHex function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(ConvertorTest, ConvertFromHexTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ConvertFromHexTest001 start"; + try { + EXPECT_EQ(Convertor::ConvertFromHex("0"), 0ULL); + EXPECT_EQ(Convertor::ConvertFromHex("a"), 10ULL); + EXPECT_EQ(Convertor::ConvertFromHex("F"), 15ULL); + EXPECT_EQ(Convertor::ConvertFromHex("G"), 0ULL); + EXPECT_EQ(Convertor::ConvertFromHex(""), 0ULL); + EXPECT_EQ(Convertor::ConvertFromHex("123456789ABCDEF0"), 0x123456789ABCDEF0ULL); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ConvertFromHexTest001 failed"; + } + GTEST_LOG_(INFO) << "ConvertFromHexTest001 end"; +} + +} // namespace Test +} // namespace FileManagement::CloudDiskService +} // namespace OHOS \ No newline at end of file diff --git a/test/unittests/clouddiskservice/sync_folder/uuid_helper_test.cpp b/test/unittests/clouddiskservice/sync_folder/uuid_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..46c8162d7fdbae2e50324c0bd7d058749f21958e --- /dev/null +++ b/test/unittests/clouddiskservice/sync_folder/uuid_helper_test.cpp @@ -0,0 +1,116 @@ +/* + * 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 +#include + +#include "uuid_helper.h" +#include "utils_log.h" + +namespace OHOS { +namespace FileManagement::CloudDiskService { +namespace Test { +using namespace testing::ext; +using namespace std; + +class UuidHelperTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void UuidHelperTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void UuidHelperTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void UuidHelperTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void UuidHelperTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: GenerateUuidTest001 + * @tc.desc: Verify the GenerateUuid function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(UuidHelperTest, GenerateUuidTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GenerateUuidTest001 start"; + try { + string uuid = UuidHelper::GenerateUuid(); + EXPECT_EQ(uuid.length(), 36); + EXPECT_TRUE(uuid.find('-') != string::npos); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GenerateUuidTest001 failed"; + } + GTEST_LOG_(INFO) << "GenerateUuidTest001 end"; +} + +/** + * @tc.name: GenerateUuidWithoutDelimTest001 + * @tc.desc: Verify the GenerateUuidWithoutDelim function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(UuidHelperTest, GenerateUuidWithoutDelimTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GenerateUuidWithoutDelimTest001 start"; + try { + string uuid = UuidHelper::GenerateUuidWithoutDelim(); + EXPECT_EQ(uuid.length(), 32); + EXPECT_TRUE(uuid.find('-') == string::npos); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GenerateUuidWithoutDelimTest001 failed"; + } + GTEST_LOG_(INFO) << "GenerateUuidWithoutDelimTest001 end"; +} + +/** + * @tc.name: GenerateUuidOnlyTest001 + * @tc.desc: Verify the GenerateUuidOnly function + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(UuidHelperTest, GenerateUuidOnlyTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GenerateUuidOnlyTest001 start"; + try { + string uuid = UuidHelper::GenerateUuidOnly(); + EXPECT_EQ(uuid.length(), 16); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "GenerateUuidOnlyTest001 failed"; + } + GTEST_LOG_(INFO) << "GenerateUuidOnlyTest001 end"; +} +} // namespace Test +} // namespace FileManagement::CloudDiskService +} // namespace OHOS \ No newline at end of file