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..2c1297d45c774634107c86e36b150a0ace719429 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, int 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/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index c25212f5d2189f34823469e5804f00e1bcdd77c9..a0a38653c8b6f74d276b29455b6b2400c2a26998 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -47,6 +47,24 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) { try { auto restore = make_shared(callbacks); + ServiceProxy::InvaildInstance(); + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + HILOGI("Failed to get backup service"); + return nullptr; + } + BSessionRestore::Callbacks callbacksTmp {.onFileReady = callbacks.onFileReady, + .onBundleStarted = callbacks.onBundleStarted, + .onBundleFinished = callbacks.onBundleFinished, + .onAllBundlesFinished = callbacks.onAllBundlesFinished, + .onBackupServiceDied = callbacks.onBackupServiceDied}; + int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacksTmp)); + if (res != 0) { + HILOGE("Failed to Restore because of %{public}d", res); + return nullptr; + } + + restore->RegisterBackupServiceDied(callbacks.onBackupServiceDied); return restore; } catch (const exception &e) { HILOGE("Failed to Restore because of %{public}s", e.what()); @@ -78,18 +96,12 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, RestoreTypeEnum restoreType, int32_t userId) { - { - std::unique_lock lock(mutex_); - workList_.push({move(remoteCap), move(bundlesToRestore), restoreType, userId}); - } - - if (isAppend_.exchange(true)) { - return ERR_OK; - } else { - PopBundleInfo(); + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return ERR_OK; + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); } void BSessionRestoreAsync::RegisterBackupServiceDied(std::function functor) @@ -107,76 +119,4 @@ void BSessionRestoreAsync::RegisterBackupServiceDied(std::function funct deathRecipient_ = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient_); } - -void BSessionRestoreAsync::OnBackupServiceDied() -{ - HILOGE("Backup service died"); - if (callbacks_.onBackupServiceDied) { - callbacks_.onBackupServiceDied(); - } - deathRecipient_ = nullptr; - ServiceProxy::InvaildInstance(); - PopBundleInfo(); -} - -void BSessionRestoreAsync::PopBundleInfo() -{ - HILOGE("Start"); - AppendBundleInfo info; - isAppend_.store(true); - { - std::unique_lock lock(mutex_); - if (workList_.empty()) { - isAppend_.store(false); - return; - } - info = move(workList_.front()); - workList_.pop(); - } - AppendBundlesImpl(move(info)); -} - -void BSessionRestoreAsync::AppendBundlesImpl(AppendBundleInfo info) -{ - HILOGD("Start"); - ServiceProxy::InvaildInstance(); - auto proxy = ServiceProxy::GetInstance(); - if (proxy == nullptr) { - return OnBundleStarted(BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(), - info.bundlesToRestore); - } - auto onBackupServiceDied = bind(&BSessionRestoreAsync::OnBackupServiceDied, shared_from_this()); - RegisterBackupServiceDied(onBackupServiceDied); - - BSessionRestore::Callbacks callbacksTmp {.onFileReady = callbacks_.onFileReady, - .onBundleStarted = callbacks_.onBundleStarted, - .onBundleFinished = callbacks_.onBundleFinished, - .onAllBundlesFinished = callbacks_.onAllBundlesFinished, - .onBackupServiceDied = onBackupServiceDied}; - int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacksTmp)); - if (res != 0) { - HILOGE("Failed to Init Restore because of %{public}d", res); - BError(BError::Codes::SDK_BROKEN_IPC, "Failed to int restore session").GetCode(); - return OnBundleStarted(res, info.bundlesToRestore); - } - for (auto &bundleName : info.bundlesToRestore) { - HILOGD("Append bundleName: %{public}s", bundleName.c_str()); - } - res = - proxy->AppendBundlesRestoreSession(move(info.remoteCap), info.bundlesToRestore, info.restoreType, info.userId); - if (res != 0) { - HILOGE("Failed to Restore because of %{public}d", res); - BError(BError::Codes::SDK_BROKEN_IPC, "Failed to append bundles").GetCode(); - return OnBundleStarted(res, info.bundlesToRestore); - } -} - -void BSessionRestoreAsync::OnBundleStarted(ErrCode errCode, const vector &bundlesToRestore) -{ - for (auto &bundleName : bundlesToRestore) { - if (callbacks_.onBundleStarted) { - callbacks_.onBundleStarted(errCode, bundleName); - } - } -} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/common/src/sandbox_helper.cpp b/interfaces/common/src/sandbox_helper.cpp index fb70c5dec6f5a8262f8037582d438e3cdc23e31e..140fb61e92a30718a408d1c3b09846d0417a2742 100644 --- a/interfaces/common/src/sandbox_helper.cpp +++ b/interfaces/common/src/sandbox_helper.cpp @@ -280,12 +280,11 @@ int32_t SandboxHelper::GetPhysicalPath(const std::string &fileUri, const std::st { Uri uri(fileUri); string bundleName = uri.GetAuthority(); - string sandboxPath = SandboxHelper::Decode(uri.GetPath()); - if (bundleName == MEDIA) { - return GetMediaPhysicalPath(sandboxPath, userId, physicalPath); + return GetMediaPhysicalPath(uri.GetPath(), userId, physicalPath); } + string sandboxPath = SandboxHelper::Decode(uri.GetPath()); if ((sandboxPath.find(FILE_MANAGER_URI_HEAD) == 0 && bundleName != FILE_MANAGER_AUTHORITY) || (sandboxPath.find(FUSE_URI_HEAD) == 0 && bundleName != DLP_MANAGER_BUNDLE_NAME)) { return -EINVAL; diff --git a/interfaces/kits/js/file_share/grant_permissions.cpp b/interfaces/kits/js/file_share/grant_permissions.cpp index 7eccff7aee7757b7408480bbca9344b504d03aec..6d7ec0f4a6f7e6789902ee7682cda3c172dbff1f 100644 --- a/interfaces/kits/js/file_share/grant_permissions.cpp +++ b/interfaces/kits/js/file_share/grant_permissions.cpp @@ -34,7 +34,7 @@ using namespace std; namespace { const std::string FILE_ACCESS_PERMISSION = "ohos.permission.FILE_ACCESS_PERSIST"; const std::string SET_SANDBOX_POLICY_PERMISSION = "ohos.permission.SET_SANDBOX_POLICY"; -const char *g_fullMountEnableParameter = "const.filemanager.full_mout.enable"; +const char *g_fullMountEnableParameter = "const.filemanager.full_mount.enable"; static bool IsSystemApp() { diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index ba9538812a329db80235876a597e5b7fc9a520d9..2a2e639bc4a1d20d78663e46d62619a1e00fc83a 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -97,7 +97,13 @@ public: * */ void SendAppGalleryNotify(const std::string &bundleName); - + + /** + * @brief 结束会话删除session,卸载服务 + * + */ + void SessionDeactive(); + public: explicit Service(int32_t saID, bool runOnCreate = false) : SystemAbility(saID, runOnCreate) { diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 0c530e3cc4c30d8093850c85c7f5fa46bbdcd6d7..ff45a9c2f4461e022952fa230d0ecb1c8626d604 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -76,6 +76,7 @@ public: [RESTORE] Support for multiple users, incoming during restore process. */ int32_t userId {100}; + RestoreTypeEnum restoreDataType {RESTORE_DATA_WAIT_SEND}; }; public: @@ -405,6 +406,12 @@ public: */ void DecreaseSessionCnt(); + /** + * @brief clear session data + * + */ + void ClearSessionData(); + private: /** * @brief 获取backup extension ability diff --git a/services/backup_sa/include/module_sched/sched_scheduler.h b/services/backup_sa/include/module_sched/sched_scheduler.h index 30415c6c14a4151f14be559572fce7b69ffd343a..507c4caee1bc1f7f0fc2dbc9de03d1cd662d95fa 100644 --- a/services/backup_sa/include/module_sched/sched_scheduler.h +++ b/services/backup_sa/include/module_sched/sched_scheduler.h @@ -68,6 +68,18 @@ public: */ void TryUnloadServiceTimer(bool force = false); + /** + * @brief clear scheduler data + * + */ + void ClearSchedulerData(); + + /** + * @brief unload service + * + */ + void TryUnloadService(); + void StartTimer() { extTime_.Setup(); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index aedb2327731880814acbf5c613165db68b51d23b..cddd070752f34f67ed6823954444549645c1c037 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -826,4 +826,22 @@ void Service::SendAppGalleryNotify(const BundleName &bundleName) bundleName.c_str()); } } + +void Service::SessionDeactive() +{ + try { + HILOGI("Begin"); + // 结束定时器 + sched_->ClearSchedulerData(); + // 清除缓存数据 + session_->ClearSessionData(); + // 清除session + session_->Deactive(nullptr, true); + // 卸载服务 + sched_->TryUnloadService(); + } catch (...) { + HILOGI("Unexpected exception"); + return; + } +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index f6b89f44a216bfa7d1a0c339182d276cb18db985..4f78c7e0d3503caacc05e310c65ac87c1a0c4d47 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -269,7 +269,7 @@ void SvcSessionManager::InitClient(Impl &newImpl) HILOGW("It's curious that the backup sa dies before the backup client"); return; } - (void)revPtrStrong->StopAll(obj); + (void)revPtrStrong->SessionDeactive(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); remoteObj->AddDeathRecipient(deathRecipient_); @@ -427,9 +427,7 @@ bool SvcSessionManager::IsOnAllBundlesFinished() if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); } - auto iter = find_if(impl_.backupExtNameMap.begin(), impl_.backupExtNameMap.end(), - [](const auto &it) { return it.second.isBundleFinished == false; }); - bool isAllBundlesFinished = (iter == impl_.backupExtNameMap.end() && impl_.isAppendFinish); + bool isAllBundlesFinished = !impl_.backupExtNameMap.size(); if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); isAllBundlesFinished = (isAllBundlesFinished && isAllBundlesRestored); @@ -502,6 +500,9 @@ bool SvcSessionManager::GetNeedToInstall(const std::string &bundleName) bool SvcSessionManager::NeedToUnloadService() { unique_lock lock(lock_); + if (impl_.restoreDataType == RestoreTypeEnum::RESTORE_DATA_READDY) { + return false; + } bool isNeedToUnloadService = (!impl_.backupExtNameMap.size() && (sessionCnt_.load() <= 0)); if (impl_.scenario == IServiceReverse::Scenario::RESTORE) { bool isAllBundlesRestored = SvcRestoreDepsManager::GetInstance().IsAllBundlesRestored(); @@ -520,6 +521,7 @@ void SvcSessionManager::SetBundleRestoreType(const std::string &bundleName, Rest auto it = GetBackupExtNameMap(bundleName); it->second.restoreType = restoreType; + impl_.restoreDataType = restoreType; } RestoreTypeEnum SvcSessionManager::GetBundleRestoreType(const std::string &bundleName) @@ -658,4 +660,20 @@ void SvcSessionManager::DecreaseSessionCnt() HILOGE("Invalid sessionCount."); } } + +void SvcSessionManager::ClearSessionData() +{ + unique_lock lock(lock_); + for (auto it = impl_.backupExtNameMap.begin(); it != impl_.backupExtNameMap.end();) { + // clear timer + extBundleTimer.Unregister(it->second.extTimerId); + // disconnect extension + if (it->second.schedAction == BConstants::ServiceSchedAction::RUNNING) { + it->second.backUpConnection->DisconnectBackupExtAbility(); + } + // clear data + it->second.schedAction = BConstants::ServiceSchedAction::FINISH; + } + impl_.backupExtNameMap.clear(); +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 658fe501f9112f55acef0b87f9de0dd3cc3c13d4..3453bbdd4b7fc7c1c4f52fc023f2f4dda8e544ce 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -210,6 +210,32 @@ void SchedScheduler::TryUnloadServiceTimer(bool force) tryUnload(); } +void SchedScheduler::TryUnloadService() +{ + HILOGI("Unload system ability"); + sptr saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + HILOGE("UnloadSA, GetSystemAbilityManager is null."); + return; + } + int32_t result = saManager->UnloadSystemAbility(FILEMANAGEMENT_BACKUP_SERVICE_SA_ID); + if (result != ERR_OK) { + HILOGE("UnloadSA, UnloadSystemAbility result: %{public}d", result); + return; + } +} + +void SchedScheduler::ClearSchedulerData() +{ + unique_lock lock(lock_); + for (auto &bundleTime : bundleTimeVec_) { + auto &[bName, iTime] = bundleTime; + extTime_.Unregister(iTime); + } + bundleTimeVec_.clear(); + threadPool_.Stop(); +} + void SchedScheduler::InstallSuccess(const std::string &bundleName, const int32_t resultCode) { if (!resultCode) { diff --git a/test/unittest/file_share_native/file_share_test.cpp b/test/unittest/file_share_native/file_share_test.cpp index 0af2942fbd4c54dc67fe3617ed170f5323200c62..b57eb4ba50e90aafd735c5b855fb8a84714fa0d7 100644 --- a/test/unittest/file_share_native/file_share_test.cpp +++ b/test/unittest/file_share_native/file_share_test.cpp @@ -389,11 +389,18 @@ HWTEST_F(FileShareTest, File_share_GetPhysicalPath_0004, testing::ext::TestSize. HWTEST_F(FileShareTest, File_share_GetPhysicalPath_0005, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FileShareTest-begin File_share_GetPhysicalPath_0005"; - std::string fileUri = "file://media/Photo/12/IMG_12345_999999/test.jpg"; + std::string strPrefix = "file://media/"; + std::string fileUri = "Photo/12/IMG_12345_999999/test.jpg"; std::string physicalPath; - int32_t ret = SandboxHelper::GetPhysicalPath(fileUri, "100", physicalPath); + int32_t ret = SandboxHelper::GetPhysicalPath(strPrefix + SandboxHelper::Encode(fileUri), "100", physicalPath); EXPECT_EQ(ret, E_OK); EXPECT_EQ(physicalPath, "/mnt/hmdfs/100/account/cloud_merge_view/files/Photo/575/IMG_12345_999999.jpg"); + + std::string fileUri2 = "Photo/12/IMG_12345_999999/test .jpg"; + std::string physicalPath2; + ret = SandboxHelper::GetPhysicalPath(strPrefix + SandboxHelper::Encode(fileUri2), "100", physicalPath2); + EXPECT_EQ(ret, E_OK); + EXPECT_EQ(physicalPath2, "/mnt/hmdfs/100/account/cloud_merge_view/files/Photo/575/IMG_12345_999999.jpg"); GTEST_LOG_(INFO) << "FileShareTest-end File_share_GetPhysicalPath_0005"; } diff --git a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp index 76ddbb901ceb294e967045f6302af2d3c09e236e..4068bd936ab84ae53c40831bd299431cf1510fdb 100644 --- a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp +++ b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp @@ -96,11 +96,5 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, void BSessionRestoreAsync::OnBackupServiceDied() {} -void BSessionRestoreAsync::PopBundleInfo() {} - -void BSessionRestoreAsync::AppendBundlesImpl(AppendBundleInfo info) {} - -void BSessionRestoreAsync::OnBundleStarted(ErrCode errCode, const vector &bundlesToRestore) {} - void BSessionRestoreAsync::RegisterBackupServiceDied(function functor) {} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 372961277934858113b64f954db04f2e0cb6b152..898c0f8351b7d1b500675630cdde2771fc179340 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -127,4 +127,6 @@ void Service::OnAllBundlesFinished(ErrCode errCode) {} void Service::OnStartSched() {} void Service::SendAppGalleryNotify(const BundleName &bundleName) {} + +void Service::SessionDeactive() {} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 604c4e7430f2f69c31a022e4aae5f510c4d15fba..012ff46825a1566ccd17a8d8ae7f88bd6790b235 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -325,4 +325,6 @@ void SvcSessionManager::SetBackupExtName(const string &bundleName, const string void SvcSessionManager::IncreaseSessionCnt() {} void SvcSessionManager::DecreaseSessionCnt() {} + +void SvcSessionManager::ClearSessionData() {} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_sched/sched_scheduler_mock.cpp b/tests/mock/module_sched/sched_scheduler_mock.cpp index b44f94ebda831533147264244aff7d4a5c955432..264efd809f8050764aac73d1d16059eec044142d 100644 --- a/tests/mock/module_sched/sched_scheduler_mock.cpp +++ b/tests/mock/module_sched/sched_scheduler_mock.cpp @@ -34,5 +34,9 @@ void SchedScheduler::InstallingState(const string &bundleName) {} void SchedScheduler::TryUnloadServiceTimer(bool force) {} +void SchedScheduler::TryUnloadService() {} + +void SchedScheduler::ClearSchedulerData() {} + void SchedScheduler::InstallSuccess(const std::string &bundleName, const int32_t resultCode) {} }; // namespace OHOS::FileManagement::Backup \ No newline at end of file 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..e9badac6b36cf72a9dafa31b8a0e2a9881eb4a37 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,30 @@ 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"; +} } // 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/tools/backup_tool/src/tools_op_restore_async.cpp b/tools/backup_tool/src/tools_op_restore_async.cpp index 79c3a16ee57179624d0d222b60eb38856f9cab39..146ae8f83660e8b3fe1cfd77a6aaf5e75d2f5f18 100644 --- a/tools/backup_tool/src/tools_op_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_restore_async.cpp @@ -50,6 +50,9 @@ public: if (flag == true) { ready_ = true; cv_.notify_all(); + } else if (cnt_ == 0) { + ready_ = true; + cv_.notify_all(); } } @@ -59,12 +62,24 @@ public: cv_.wait(lk, [&] { return ready_; }); } + void UpdateBundleFinishedCount() + { + lock_guard lk(lock_); + cnt_--; + } + + void SetBundleFinishedCount(uint32_t cnt) + { + cnt_ = cnt; + } + shared_ptr session_ = {}; private: mutable condition_variable cv_; mutex lock_; bool ready_ = false; + uint32_t cnt_ {0}; }; static string GenHelpMsg() @@ -111,7 +126,8 @@ static void OnBundleStarted(shared_ptr ctx, ErrCode err, const Bun { printf("BundleStarted errCode = %d, BundleName = %s\n", err, name.c_str()); if (err != 0) { - ctx->TryNotify(true); + ctx->UpdateBundleFinishedCount(); + ctx->TryNotify(); } } @@ -119,16 +135,15 @@ static void OnBundleFinished(shared_ptr ctx, ErrCode err, const Bu { printf("BundleFinished errCode = %d, BundleName = %s\n", err, name.c_str()); if (err != 0) { - ctx->TryNotify(true); + ctx->UpdateBundleFinishedCount(); + ctx->TryNotify(); } } static void OnAllBundlesFinished(shared_ptr ctx, ErrCode err) { printf("all bundles finished end\n"); - if (err != 0) { - ctx->TryNotify(true); - } + ctx->TryNotify(true); } static void OnBackupServiceDied(shared_ptr ctx) @@ -267,7 +282,7 @@ static int32_t InitArg(const string &pathCapFile, FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return -EPERM; } - + ctx->SetBundleFinishedCount(bundleNames.size()); return AppendBundles(ctx, pathCapFile, bundleNames, type, userId); } 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/";