diff --git a/frameworks/native/backup_ext/include/tar_file.h b/frameworks/native/backup_ext/include/tar_file.h index 5b9dbd3d11a0ad16f70b71992d0e13a523ee76fe..4e1a8a28e10653eb300c3027d7c6d4bdae1f0328 100644 --- a/frameworks/native/backup_ext/include/tar_file.h +++ b/frameworks/native/backup_ext/include/tar_file.h @@ -47,7 +47,7 @@ const uint32_t TSIZE_BASE = 124; const uint32_t TMTIME_BASE = 136; const uint32_t CHKSUM_BASE = 148; const uint32_t BLOCK_SIZE = 512; -const uint64_t READ_BUFF_SIZE = 512 * 1024; +const off_t READ_BUFF_SIZE = 512 * 1024; const uint8_t BLANK_SPACE = 0x20; const uint64_t MB_TO_BYTE = 1024 * 1024; const std::string TMAGIC = "ustar"; @@ -56,7 +56,7 @@ const char AREGTYPE = '\0'; // regular file const char SYMTYPE = '2'; // reserved const char DIRTYPE = '5'; // directory const char GNUTYPE_LONGNAME = 'L'; -} +} // namespace // 512 bytes using TarHeader = struct { @@ -127,7 +127,7 @@ private: * @param read 读取文件 * @param isFilled 是否写完 */ - int SplitWriteAll(const std::vector &ioBuffer, int read, bool &isFilled); + off_t SplitWriteAll(const std::vector &ioBuffer, off_t read, bool &isFilled); /** * @brief creaat split tarfile @@ -176,7 +176,7 @@ private: * @param iobuffer 文件信息数组 * @param size 文件大小 */ - int ReadAll(int fd, std::vector &ioBuffer, off_t size); + off_t ReadAll(int fd, std::vector &ioBuffer, off_t size); /** * @brief write files diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 5dcc23aeb2326bee3d5d61471a9c430a7aa6735d..083e4d7d442e3717b74e3b3d54af96e42b9de4b8 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -522,6 +522,45 @@ static bool RestoreBigFilePrecheck(string& fileName, const string& path, return true; } +static void RestoreBigFileAfter(const string& fileName, const string& filePath, const struct stat& sta, + const set& lks) +{ + if (chmod(filePath.c_str(), sta.st_mode) != 0) { + HILOGE("Failed to chmod filePath, err = %{public}d", errno); + } + + if (fileName != filePath) { + auto resolvedFileName = make_unique(PATH_MAX); + auto resolvedFilePath = make_unique(PATH_MAX); + bool allOk = true; + if (!realpath(fileName.data(), resolvedFileName.get())) { + HILOGE("failed to real path for fileName"); + allOk = false; + } + if (!realpath(filePath.data(), resolvedFilePath.get())) { + HILOGE("failed to real path for filePath"); + allOk = false; + } + if (allOk && string_view(resolvedFileName.get()) != string_view(resolvedFilePath.get())) { + if (!RemoveFile(fileName)) { + HILOGE("Failed to delete the big file"); + } + } + } + + for (const auto &lksPath : lks) { + if (link(filePath.data(), lksPath.data())) { + HILOGE("failed to create hard link file, errno : %{public}d", errno); + } + } + + struct timespec tv[2] = {sta.st_atim, sta.st_mtim}; + UniqueFd fd(open(filePath.data(), O_RDONLY)); + if (futimens(fd.Get(), tv) != 0) { + HILOGI("failed to change the file time. %{public}s , %{public}d", filePath.c_str(), errno); + } +} + static void RestoreBigFiles(bool appendTargetPath) { // 获取索引文件内容 @@ -537,7 +576,6 @@ static void RestoreBigFiles(bool appendTargetPath) string fileName = path + item.hashName; string filePath = appendTargetPath ? (path + item.fileName) : item.fileName; - struct stat sta = item.sta; if (!RestoreBigFilePrecheck(fileName, path, item.hashName, filePath)) { continue; @@ -547,26 +585,8 @@ static void RestoreBigFiles(bool appendTargetPath) HILOGE("failed to copy the file. err = %{public}d", errno); continue; } - if (chmod(filePath.c_str(), item.sta.st_mode) != 0) { - HILOGE("Failed to chmod %{public}s, err = %{public}d", filePath.c_str(), errno); - } - if (fileName != filePath) { - if (!RemoveFile(fileName)) { - HILOGE("Failed to delete the big file %{public}s", fileName.c_str()); - } - } - set lks = cache.GetHardLinkInfo(item.hashName); - for (const auto &lksPath : lks) { - if (link(filePath.data(), lksPath.data())) { - HILOGE("failed to create hard link file %{public}s errno : %{public}d", lksPath.c_str(), errno); - } - } - - struct timespec tv[2] = {sta.st_atim, sta.st_mtim}; - UniqueFd fd(open(filePath.data(), O_RDONLY)); - if (futimens(fd.Get(), tv) != 0) { - HILOGI("failed to change the file time. %{public}s , %{public}d", filePath.c_str(), errno); - } + + RestoreBigFileAfter(fileName, filePath, item.sta, cache.GetHardLinkInfo(item.hashName)); } } @@ -700,6 +720,11 @@ void BackupExtExtension::DoClear() if (!ForceRemoveDirectory(restoreCache)) { HILOGI("Failed to delete the restore cache %{public}s", restoreCache.c_str()); } + // delete el1 backup/restore + ForceRemoveDirectory( + string(BConstants::PATH_BUNDLE_BACKUP_HOME_EL1).append(BConstants::SA_BUNDLE_BACKUP_BACKUP)); + ForceRemoveDirectory( + string(BConstants::PATH_BUNDLE_BACKUP_HOME_EL1).append(BConstants::SA_BUNDLE_BACKUP_RESTORE)); unique_lock lock(lock_); tars_.clear(); } catch (...) { diff --git a/frameworks/native/backup_ext/src/tar_file.cpp b/frameworks/native/backup_ext/src/tar_file.cpp index aa1ebee0d791db60bebe4ff751123d2d3e011507..bbb135e3f34c5dd8a0381ee70dd4f319e7746302 100644 --- a/frameworks/native/backup_ext/src/tar_file.cpp +++ b/frameworks/native/backup_ext/src/tar_file.cpp @@ -208,8 +208,8 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) bool isFilled = false; while (remain > 0) { - size_t read = ioBuffer_.size(); - if (size < ioBuffer_.size()) { + off_t read = ioBuffer_.size(); + if (size < static_cast(ioBuffer_.size())) { read = size; } else { if (read > remain) { @@ -241,13 +241,13 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) return false; } -int TarFile::SplitWriteAll(const vector &ioBuffer, int read, bool &isFilled) +off_t TarFile::SplitWriteAll(const vector &ioBuffer, off_t read, bool &isFilled) { - size_t len = ioBuffer.size(); + off_t len = ioBuffer.size(); if (len > read) { len = read; } - size_t count = 0; + off_t count = 0; while (count < len) { auto writeBytes = fwrite(&ioBuffer[count], sizeof(uint8_t), len - count, currentTarFile_); if (writeBytes < 1) { @@ -322,10 +322,10 @@ bool TarFile::FillSplitTailBlocks() void TarFile::SetCheckSum(TarHeader &hdr) { int sum = 0; - vector buffer {}; + vector buffer {}; buffer.resize(sizeof(hdr)); buffer.assign(reinterpret_cast(&hdr), reinterpret_cast(&hdr) + sizeof(hdr)); - for (int index = 0; index < BLOCK_SIZE; index++) { + for (uint32_t index = 0; index < BLOCK_SIZE; index++) { if (index < CHKSUM_BASE || index > CHKSUM_BASE + CHKSUM_LEN - 1) { sum += (buffer[index] & 0xFF); } else { @@ -339,7 +339,7 @@ void TarFile::FillOwnerName(TarHeader &hdr, const struct stat &st) { struct passwd *pw = getpwuid(st.st_uid); if (pw != nullptr) { - int ret = snprintf_s(hdr.uname, sizeof(hdr.uname), sizeof(hdr.uname) - 1, "%s", pw->pw_name); + size_t ret = snprintf_s(hdr.uname, sizeof(hdr.uname), sizeof(hdr.uname) - 1, "%s", pw->pw_name); if (ret < 0 || ret >= sizeof(hdr.uname)) { HILOGE("Fill pw_name failed, err = %{public}d", errno); } @@ -364,10 +364,10 @@ void TarFile::FillOwnerName(TarHeader &hdr, const struct stat &st) } } -int TarFile::ReadAll(int fd, vector &ioBuffer, off_t size) +off_t TarFile::ReadAll(int fd, vector &ioBuffer, off_t size) { - size_t count = 0; - size_t len = ioBuffer.size(); + off_t count = 0; + off_t len = ioBuffer.size(); if (len > size) { len = size; } diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index be201ecc5842d5845827c312d2883e8711c3cfc2..961434ce155f7b1c758416261590abb6db68d229 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -48,6 +48,11 @@ ohos_unittest("b_session_test") { "samgr:samgr_proxy", ] + defines = [ + "private=public", + "protect=public", + ] + sanitize = { cfi = true cfi_cross_dso = true diff --git a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp index 2e4990bfa1430db8d67e0b3d75922cf9713fd8ff..514116c2e01bd5ab1410a6852860973d252e8e93 100644 --- a/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_backup_test.cpp @@ -114,7 +114,7 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0100, testing::ext::Tes /** * @tc.number: SUB_backup_b_session_backup_0200 * @tc.name: SUB_backup_b_session_backup_0200 - * @tc.desc: 测试Callbacks接口 + * @tc.desc: 测试Finish接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -122,7 +122,64 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0100, testing::ext::Tes */ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0200, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0200"; + GTEST_LOG_(INFO) << "BSessionBackupTest-Finish SUB_backup_b_session_backup_0200"; + try { + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + auto ret = backupPtr_->Finish(); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + ret = backupPtr_->Finish(); + EXPECT_NE(ret, ErrCode(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionBackupTest-an exception occurred by Finish."; + } + GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0200"; +} + +/** + * @tc.number: SUB_backup_b_session_backup_0300 + * @tc.name: SUB_backup_b_session_backup_0300 + * @tc.desc: 测试AppendBundles接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionBackupTest-AppendBundles SUB_backup_b_session_backup_0300"; + try { + vector bundleNames; + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + auto ret = backupPtr_->AppendBundles(bundleNames); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + ret = backupPtr_->AppendBundles(bundleNames); + EXPECT_NE(ret, ErrCode(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionBackupTest-an exception occurred by AppendBundles."; + } + GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0300"; +} + +/** + * @tc.number: SUB_backup_b_session_backup_0400 + * @tc.name: SUB_backup_b_session_backup_0400 + * @tc.desc: 测试Callbacks接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0400"; try { Init(); BFileInfo bFileInfo("", "", 0); @@ -135,21 +192,21 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0200, testing::ext::Tes EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionBackupTest-an exception occurred by Callbacks."; } - GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0200"; + GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0400"; } /** - * @tc.number: SUB_backup_b_session_backup_0300 - * @tc.name: SUB_backup_b_session_backup_0300 + * @tc.number: SUB_backup_b_session_backup_0500 + * @tc.name: SUB_backup_b_session_backup_0500 * @tc.desc: 测试Init接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 * @tc.require: I6F3GV */ -HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0300, testing::ext::TestSize.Level1) +HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0500, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0300"; + GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0500"; try { GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); @@ -170,21 +227,21 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0300, testing::ext::Tes EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionBackupTest-an exception occurred by Init."; } - GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0300"; + GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0500"; } /** - * @tc.number: SUB_backup_b_session_backup_0400 - * @tc.name: SUB_backup_b_session_backup_0400 + * @tc.number: SUB_backup_b_session_backup_0600 + * @tc.name: SUB_backup_b_session_backup_0600 * @tc.desc: 测试RegisterBackupServiceDied接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 * @tc.require: I6F3GV */ -HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0400, testing::ext::TestSize.Level1) +HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0600, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0400"; + GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0600"; try { GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); @@ -196,21 +253,21 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0400, testing::ext::Tes EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionBackupTest-an exception occurred by RegisterBackupServiceDied."; } - GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0400"; + GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0600"; } /** - * @tc.number: SUB_backup_b_session_backup_0500 - * @tc.name: SUB_backup_b_session_backup_0500 + * @tc.number: SUB_backup_b_session_backup_0700 + * @tc.name: SUB_backup_b_session_backup_0700 * @tc.desc: 测试析构流程接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 * @tc.require: I6F3GV */ -HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0500, testing::ext::TestSize.Level1) +HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0700, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0500"; + GTEST_LOG_(INFO) << "BSessionBackupTest-begin SUB_backup_b_session_backup_0700"; try { SetMockGetInstance(true); SetMockLoadSystemAbility(true); @@ -234,6 +291,6 @@ HWTEST_F(BSessionBackupTest, SUB_backup_b_session_backup_0500, testing::ext::Tes EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionBackupTest-an exception occurred by ~BSessionBackup."; } - GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0500"; + GTEST_LOG_(INFO) << "BSessionBackupTest-end SUB_backup_b_session_backup_0700"; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp index f53da7733cd054f8ad5c4a4e21ce6f9309c17a2f..5b2b2377f5ff71387aded3927c55c90bd4040359 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp @@ -21,6 +21,7 @@ #include "b_error/b_error.h" #include "b_file_info.h" +#include "b_session_restore_async.h" #include "backup_kit_inner.h" #include "unique_fd.h" #include "utils_mock_global_variable.h" @@ -223,4 +224,150 @@ HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0500, test } GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0500"; } + +/** + * @tc.number: SUB_backup_b_session_restore_async_0600 + * @tc.name: SUB_backup_b_session_restore_async_0600 + * @tc.desc: 测试RegisterBackupServiceDied接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0600, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0600"; + try { + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + restorePtr_->RegisterBackupServiceDied(nullptr); + GTEST_LOG_(INFO) << "GetInstance is true but not equal to parameter"; + SetMockGetInstance(true); + restorePtr_->RegisterBackupServiceDied(nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by RegisterBackupServiceDied."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0600"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0700 + * @tc.name: SUB_backup_b_session_restore_async_0700 + * @tc.desc: 测试OnBackupServiceDied接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0700, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0700"; + try { + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + GTEST_LOG_(INFO) << "callbacks_.onBackupServiceDied is nullptr"; + callbacks_.onBackupServiceDied = nullptr; + restorePtr_->OnBackupServiceDied(); + GTEST_LOG_(INFO) << "callbacks_.onBackupServiceDied is not nullptr"; + Init(); + restorePtr_->OnBackupServiceDied(); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by OnBackupServiceDied."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0700"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0800 + * @tc.name: SUB_backup_b_session_restore_async_0800 + * @tc.desc: 测试PopBundleInfo接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0800, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0800"; + try { + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + GTEST_LOG_(INFO) << "LoadSystemAbility is true"; + SetMockLoadSystemAbility(true); + vector bundleNames; + restorePtr_->workList_.push({UniqueFd(-1), bundleNames, RESTORE_DATA_WAIT_SEND, -1}); + restorePtr_->PopBundleInfo(); + EXPECT_TRUE(restorePtr_->workList_.empty()); + restorePtr_->PopBundleInfo(); + EXPECT_TRUE(restorePtr_->workList_.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by PopBundleInfo."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0800"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0900 + * @tc.name: SUB_backup_b_session_restore_async_0900 + * @tc.desc: 测试AppendBundlesImpl接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0900"; + try { + vector bundleNames; + BSessionRestoreAsync::AppendBundleInfo info; + info.remoteCap = UniqueFd(-1); + info.bundlesToRestore = bundleNames; + info.restoreType = TypeRestoreTypeEnum::RESTORE_DATA_WAIT_SEND; + info.userId = -1; + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + restorePtr_->AppendBundlesImpl(move(info)); + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + restorePtr_->AppendBundlesImpl(move(info)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by AppendBundlesImpl."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0900"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_1000 + * @tc.name: SUB_backup_b_session_restore_async_1000 + * @tc.desc: 测试OnBundleStarted接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_1000, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_1000"; + try { + vector bundleNames; + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + GTEST_LOG_(INFO) << "onBundleStarted is nullptr"; + callbacks_.onBundleStarted = nullptr; + restorePtr_->OnBundleStarted(0x1000, bundleNames); + GTEST_LOG_(INFO) << "onBundleStarted is func ptr"; + Init(); + restorePtr_->OnBundleStarted(0x1000, bundleNames); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by OnBundleStarted."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_1000"; +} + } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp index d00f90d0f4c22c22545e22b594239be89de26bf7..5a2ff91017fa2acc7866ffbda33b29afddd22312 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp @@ -19,9 +19,14 @@ #include "b_error/b_error.h" #include "b_file_info.h" #include "backup_kit_inner.h" +#include "test_manager.h" #include "unique_fd.h" #include "utils_mock_global_variable.h" +#include +#include +#include + namespace OHOS::FileManagement::Backup { using namespace std; @@ -176,17 +181,17 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0300, testing::ext::T } /** - * @tc.number: SUB_backup_b_session_restore_0500 - * @tc.name: SUB_backup_b_session_restore_0500 + * @tc.number: SUB_backup_b_session_restore_0400 + * @tc.name: SUB_backup_b_session_restore_0400 * @tc.desc: 测试PublishFile接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 * @tc.require: I6F3GV */ -HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0500, testing::ext::TestSize.Level1) +HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0400, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0500"; + GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0400"; try { GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); @@ -201,21 +206,21 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0500, testing::ext::T EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by PublishFile."; } - GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0500"; + GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0400"; } /** - * @tc.number: SUB_backup_b_session_restore_0600 - * @tc.name: SUB_backup_b_session_restore_0600 + * @tc.number: SUB_backup_b_session_restore_0500 + * @tc.name: SUB_backup_b_session_restore_0500 * @tc.desc: 测试GetFileHandle接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 * @tc.require: I6F3GV */ -HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0600, testing::ext::TestSize.Level1) +HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0500, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0600"; + GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0500"; try { GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); @@ -231,13 +236,52 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0600, testing::ext::T EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by GetFileHandle."; } + GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0500"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_0600 + * @tc.name: SUB_backup_b_session_restore_0600 + * @tc.desc: 测试AppendBundles接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0600, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0600"; + try { + const string fileName = "1.tar"; + TestManager tm("SUB_backup_b_session_restore_0600"); + string filePath = tm.GetRootDirCurTest().append(fileName); + UniqueFd remoteCap( + open(filePath.data(), O_RDONLY | O_CREAT, + S_IRUSR | S_IWUSR)); + string bundleName = ""; + vector bundlesToRestore; + bundlesToRestore.emplace_back(bundleName); + + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + auto ret = restorePtr_->AppendBundles(move(remoteCap), bundlesToRestore); + EXPECT_NE(ret, ErrCode(BError::Codes::OK)); + + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + ret = restorePtr_->AppendBundles(move(remoteCap), bundlesToRestore); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by AppendBundles."; + } GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0600"; } /** * @tc.number: SUB_backup_b_session_restore_0700 * @tc.name: SUB_backup_b_session_restore_0700 - * @tc.desc: 测试RegisterBackupServiceDied接口 + * @tc.desc: 测试Finish接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -249,13 +293,16 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0700, testing::ext::T try { GTEST_LOG_(INFO) << "GetInstance is false"; SetMockGetInstance(false); - restorePtr_->RegisterBackupServiceDied(nullptr); + auto ret = restorePtr_->Finish(); + EXPECT_NE(ret, ErrCode(BError::Codes::OK)); + GTEST_LOG_(INFO) << "GetInstance is true"; SetMockGetInstance(true); - restorePtr_->RegisterBackupServiceDied(nullptr); + ret = restorePtr_->Finish(); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); } catch (...) { EXPECT_TRUE(false); - GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by RegisterBackupServiceDied."; + GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by Finish."; } GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0700"; } @@ -263,7 +310,7 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0700, testing::ext::T /** * @tc.number: SUB_backup_b_session_restore_0800 * @tc.name: SUB_backup_b_session_restore_0800 - * @tc.desc: 测试析构流程接口 + * @tc.desc: 测试RegisterBackupServiceDied接口 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -272,6 +319,32 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0700, testing::ext::T HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0800, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0800"; + try { + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + restorePtr_->RegisterBackupServiceDied(nullptr); + GTEST_LOG_(INFO) << "GetInstance is true but not equal to parameter"; + SetMockGetInstance(true); + restorePtr_->RegisterBackupServiceDied(nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by RegisterBackupServiceDied."; + } + GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0800"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_0900 + * @tc.name: SUB_backup_b_session_restore_0900 + * @tc.desc: 测试析构流程接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0900"; try { SetMockGetInstance(true); SetMockLoadSystemAbility(true); @@ -295,6 +368,6 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0800, testing::ext::T EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by ~BSessionRestore."; } - GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0800"; + GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0900"; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp index 78c891237cb5a915a6836ca700caf97f93efe849..ecc24d04a800ddc8118caebdba2c1782ac84880b 100644 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp @@ -365,6 +365,49 @@ HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100, te GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0100"; } +/** + * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 + * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101 + * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; + sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); + EXPECT_NE(loadCallback, nullptr); + int32_t systemAbilityId = 0; + // const OHOS::sptr &remoteObject = make_shared(); + // shared_ptr remoteObject = make_shared(); + sptr remoteObject = new MockIRemoteObject(); + loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); + loadCallback = nullptr; + GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0101"; +} + +/** + * @tc.number: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 + * @tc.name: SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102 + * @tc.desc: 测试 OnLoadSystemAbilitySuccess 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceProxyTest, SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; + sptr loadCallback = new ServiceProxy::ServiceProxyLoadCallback(); + EXPECT_NE(loadCallback, nullptr); + int32_t systemAbilityId = 0; + loadCallback->OnLoadSystemAbilitySuccess(systemAbilityId, nullptr); + loadCallback = nullptr; + GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_OnLoadSystemAbilitySuccess_0102"; +} + /** * @tc.number: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 * @tc.name: SUB_Service_proxy_OnLoadSystemAbilityFail_0100 @@ -412,4 +455,20 @@ HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetInstance_0100, testing::ext::Tes EXPECT_NE(proxy, nullptr); GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetInstance_0100"; } + +/** + * @tc.number: SUB_Service_proxy_InvaildInstance_0100 + * @tc.name: SUB_Service_proxy_InvaildInstance_0100 + * @tc.desc: 测试 InvaildInstance 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InvaildInstance_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_InvaildInstance_0100"; + ServiceProxy::InvaildInstance(); + GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InvaildInstance_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp index 85e949400396ada5510f31b6cce5ad16eda75cd9..7aa0ecfeb58486b75b12efafa3b7b36df53e70b1 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp @@ -139,6 +139,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0100, t GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnFileReady_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnFileReady_0101 + * @tc.name: SUB_backup_ServiceReverse_BackupOnFileReady_0101 + * @tc.desc: 测试 BackupOnFileReady 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0101"; + try { + Init(IServiceReverse::Scenario::RESTORE); + service_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnFileReady."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnFileReady_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnFileReady_0102 + * @tc.name: SUB_backup_ServiceReverse_BackupOnFileReady_0102 + * @tc.desc: 测试 BackupOnFileReady 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnFileReady_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnFileReady_0102"; + try { + Init(IServiceReverse::Scenario::BACKUP, 1); + service_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnFileReady."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnFileReady_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_BackupOnBundleStarted_0100 * @tc.name: SUB_backup_ServiceReverse_BackupOnBundleStarted_0100 @@ -162,6 +206,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_010 GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnBundleStarted_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnBundleStarted_0101 + * @tc.name: SUB_backup_ServiceReverse_BackupOnBundleStarted_0101 + * @tc.desc: 测试 BackupOnBundleStarted 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0101"; + try { + Init(IServiceReverse::Scenario::RESTORE); + service_->BackupOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnBundleStarted."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnBundleStarted_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnBundleStarted_0102 + * @tc.name: SUB_backup_ServiceReverse_BackupOnBundleStarted_0102 + * @tc.desc: 测试 BackupOnBundleStarted 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleStarted_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleStarted_0102"; + try { + Init(IServiceReverse::Scenario::BACKUP, 1); + service_->BackupOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnBundleStarted."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnBundleStarted_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_BackupOnBundleFinished_0100 * @tc.name: SUB_backup_ServiceReverse_BackupOnBundleFinished_0100 @@ -185,6 +273,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_01 GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnBundleFinished_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnBundleFinished_0101 + * @tc.name: SUB_backup_ServiceReverse_BackupOnBundleFinished_0101 + * @tc.desc: 测试 BackupOnBundleFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0101"; + try { + Init(IServiceReverse::Scenario::RESTORE); + service_->BackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnBundleFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnBundleFinished_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnBundleFinished_0102 + * @tc.name: SUB_backup_ServiceReverse_BackupOnBundleFinished_0102 + * @tc.desc: 测试 BackupOnBundleFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnBundleFinished_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnBundleFinished_0102"; + try { + Init(IServiceReverse::Scenario::BACKUP, 1); + service_->BackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnBundleFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnBundleFinished_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0100 * @tc.name: SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0100 @@ -208,6 +340,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinishe GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101 + * @tc.name: SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101 + * @tc.desc: 测试 BackupOnAllBundlesFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101"; + try { + Init(IServiceReverse::Scenario::RESTORE); + service_->BackupOnAllBundlesFinished(BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnAllBundlesFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102 + * @tc.name: SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102 + * @tc.desc: 测试 BackupOnAllBundlesFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102"; + try { + Init(IServiceReverse::Scenario::BACKUP, 1); + service_->BackupOnAllBundlesFinished(BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by BackupOnAllBundlesFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_BackupOnAllBundlesFinished_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_RestoreOnFileReady_0100 * @tc.name: SUB_backup_ServiceReverse_RestoreOnFileReady_0100 @@ -231,6 +407,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0100, GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnFileReady_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnFileReady_0101 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnFileReady_0101 + * @tc.desc: 测试 RestoreOnFileReady 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0101"; + try { + Init(IServiceReverse::Scenario::BACKUP); + service_->RestoreOnFileReady(BUNDLE_NAME, FILE_NAME, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnFileReady."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnFileReady_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnFileReady_0102 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnFileReady_0102 + * @tc.desc: 测试 RestoreOnFileReady 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnFileReady_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnFileReady_0102"; + try { + Init(IServiceReverse::Scenario::RESTORE, 1); + service_->RestoreOnFileReady(BUNDLE_NAME, FILE_NAME, -1); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnFileReady."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnFileReady_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100 * @tc.name: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100 @@ -254,6 +474,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_01 GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnBundleStarted_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101 + * @tc.desc: 测试 RestoreOnBundleStarted 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101"; + try { + Init(IServiceReverse::Scenario::BACKUP); + service_->RestoreOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnBundleStarted."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnBundleStarted_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102 + * @tc.desc: 测试 RestoreOnBundleStarted 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102"; + try { + Init(IServiceReverse::Scenario::RESTORE, 1); + service_->RestoreOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnBundleStarted."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnBundleStarted_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_RestoreOnBundleFinished_0100 * @tc.name: SUB_backup_ServiceReverse_RestoreOnBundleFinished_0100 @@ -277,6 +541,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0 GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnBundleFinished_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101 + * @tc.desc: 测试 RestoreOnBundleFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101"; + try { + Init(IServiceReverse::Scenario::BACKUP); + service_->RestoreOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnBundleFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnBundleFinished_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102 + * @tc.desc: 测试 RestoreOnBundleFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102"; + try { + Init(IServiceReverse::Scenario::RESTORE, 1); + service_->RestoreOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnBundleFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnBundleFinished_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0100 * @tc.name: SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0100 @@ -300,6 +608,50 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinish GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0100"; } +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101 + * @tc.desc: 测试 RestoreOnAllBundlesFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101"; + try { + Init(IServiceReverse::Scenario::BACKUP); + service_->RestoreOnAllBundlesFinished(BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnAllBundlesFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0101"; +} + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102 + * @tc.desc: 测试 RestoreOnAllBundlesFinished 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102"; + try { + Init(IServiceReverse::Scenario::RESTORE, 1); + service_->RestoreOnAllBundlesFinished(BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnAllBundlesFinished."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnAllBundlesFinished_0102"; +} + /** * @tc.number: SUB_backup_ServiceReverse_0200 * @tc.name: SUB_backup_ServiceReverse_0200 @@ -325,6 +677,31 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0200, testing::ext::TestS GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_0200"; } +/** + * @tc.number: SUB_backup_ServiceReverse_0201 + * @tc.name: SUB_backup_ServiceReverse_0201 + * @tc.desc: 测试分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0201, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0201"; + try { + Init(IServiceReverse::Scenario::RESTORE, 0); + service_->RestoreOnFileReady(BUNDLE_NAME, FILE_NAME, -1); + service_->RestoreOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); + service_->RestoreOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + service_->RestoreOnAllBundlesFinished(BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_0201"; +} + /** * @tc.number: SUB_backup_ServiceReverse_0300 * @tc.name: SUB_backup_ServiceReverse_0300 @@ -349,4 +726,29 @@ HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0300, testing::ext::TestS } GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_0300"; } + +/** + * @tc.number: SUB_backup_ServiceReverse_0301 + * @tc.name: SUB_backup_ServiceReverse_0301 + * @tc.desc: 测试分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_0301, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_0301"; + try { + Init(IServiceReverse::Scenario::BACKUP, 0); + service_->BackupOnFileReady(BUNDLE_NAME, FILE_NAME, -1); + service_->BackupOnBundleStarted(BError(BError::Codes::OK), BUNDLE_NAME); + service_->BackupOnBundleFinished(BError(BError::Codes::OK), BUNDLE_NAME); + service_->BackupOnAllBundlesFinished(BError(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_0301"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp b/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp index 3aa8898c6f3e1dc0009cf9e95d3f80b7363df16a..2cebb5ad9f746b921925adac923302d4649761b3 100644 --- a/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_json_cached_entity_test.cpp @@ -59,6 +59,156 @@ HWTEST_F(BJsonCachedEntityTest, b_json_construction_0100, testing::ext::TestSize GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_construction_0100"; } +/** + * @tc.number: SUB_backup_b_json_construction_0101 + * @tc.name: b_json_construction_0101 + * @tc.desc: Test function of construction interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0101, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0101"; + try { + TestManager tm("b_json_construction_0101"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ""; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDWR | O_CREAT, 0600))); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_construction_0101"; +} + +/** + * @tc.number: SUB_backup_b_json_construction_0102 + * @tc.name: b_json_construction_0102 + * @tc.desc: Test function of construction interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0102, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0102"; + try { + TestManager tm("b_json_construction_0102"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ".json"; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDWR | O_CREAT, NULL))); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_construction_0102"; +} + +/** + * @tc.number: SUB_backup_b_json_construction_0104 + * @tc.name: b_json_construction_0104 + * @tc.desc: Test function of construction interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0104, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0104"; + try { + TestManager tm("b_json_construction_0104"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ".json"; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDONLY, NULL))); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_construction_0104"; +} + +/** + * @tc.number: SUB_backup_b_json_construction_0105 + * @tc.name: b_json_construction_0105 + * @tc.desc: Test function of construction interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0105, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0105"; + try { + TestManager tm("b_json_construction_0105"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ""; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDWR | O_CREAT, NULL))); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_construction_0105"; +} + +/** + * @tc.number: SUB_backup_b_json_construction_0106 + * @tc.name: b_json_construction_0106 + * @tc.desc: Test function of construction interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0106, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0106"; + try { + TestManager tm("b_json_construction_0106"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ""; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDONLY, 0600))); + } catch (...) { + EXPECT_TRUE(true); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_construction_0106"; +} + +/** + * @tc.number: SUB_backup_b_json_construction_0107 + * @tc.name: b_json_construction_0107 + * @tc.desc: Test function of construction interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_construction_0107, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_construction_0107"; + try { + TestManager tm("b_json_construction_0107"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ""; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDONLY, NULL))); + } catch (...) { + EXPECT_TRUE(true); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_construction_0107"; +} + /** * @tc.number: SUB_backup_b_json_Structuralize_0100 * @tc.name: b_json_Structuralize_0100 @@ -110,4 +260,85 @@ HWTEST_F(BJsonCachedEntityTest, b_json_GetFd_0100, testing::ext::TestSize.Level0 } GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_GetFd_0100"; } + +/** + * @tc.number: SUB_backup_b_json_Persist_0100 + * @tc.name: b_json_Persist_0100 + * @tc.desc: Test function of Persist interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_Persist_0100, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_Persist_0100"; + try { + TestManager tm("b_json_Persist_0100"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ".json"; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDWR | O_CREAT, 0600))); + jce.Persist(); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_Persist_0100"; +} + +/** + * @tc.number: SUB_backup_b_json_ReloadFromFile_0100 + * @tc.name: b_json_ReloadFromFile_0100 + * @tc.desc: Test function of ReloadFromFile interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_ReloadFromFile_0100, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_ReloadFromFile_0100"; + try { + TestManager tm("b_json_ReloadFromFile_0100"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ".json"; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDWR | O_CREAT, 0600))); + int ret = jce.ReloadFromFile(); + EXPECT_EQ(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_ReloadFromFile_0100"; +} + +/** + * @tc.number: SUB_backup_b_json_ReloadFromString_0100 + * @tc.name: b_json_ReloadFromString_0100 + * @tc.desc: Test function of ReloadFromString interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonCachedEntityTest, b_json_ReloadFromString_0100, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-begin b_json_ReloadFromString_0100"; + try { + TestManager tm("b_json_ReloadFromString_0100"); + + std::string path = tm.GetRootDirCurTest(); + std::string filePath = path + ".json"; + std::string_view sv = R"({"key":1})"; + BJsonCachedEntity jce(UniqueFd(open(filePath.data(), O_RDWR | O_CREAT, 0600))); + jce.ReloadFromString(sv); + } catch (...) { + EXPECT_TRUE(true); + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonCachedEntityTest-end b_json_ReloadFromString_0100"; +} + } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index 8d486942eb3b5e313e84143dae631a5ca3d01422..8a3e99d6a7a2f6c927c72211d5f316a0ae41a8e9 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -76,6 +76,7 @@ static inline std::string_view SA_BUNDLE_BACKUP_BACKUP = "/backup/"; static inline std::string_view SA_BUNDLE_BACKUP_RESTORE = "/restore/"; static inline std::string_view SA_BUNDLE_BACKUP_TMP_DIR = "/tmp/"; static inline std::string_view BACKUP_TOOL_RECEIVE_DIR = "/data/backup/received/"; +static inline std::string_view PATH_BUNDLE_BACKUP_HOME_EL1 = "/data/storage/el1/backup"; static inline std::string_view PATH_BUNDLE_BACKUP_HOME = "/data/storage/el2/backup"; static inline std::string_view BACKUP_TOOL_LINK_DIR = "/data/backup"; static inline std::string_view BACKUP_TOOL_INSTALL_DIR = "/data/backup/install/";