diff --git a/frameworks/native/backup_ext/src/tar_file.cpp b/frameworks/native/backup_ext/src/tar_file.cpp index 51dba1aac08baeda8dd1f25141cd5e0416b03997..6f456bf84184a35f4396e467a211c7cb39144f32 100644 --- a/frameworks/native/backup_ext/src/tar_file.cpp +++ b/frameworks/native/backup_ext/src/tar_file.cpp @@ -307,7 +307,7 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size, int &err) int fd = open(fileName.c_str(), O_RDONLY | O_CLOEXEC); if (fd < 0) { err = errno; - HILOGE("Failed to open file %{public}s, err = %{public}d", fileName.data(), errno); + HILOGE("Failed to open file %{public}s, err = %{public}d", GetAnonyString(fileName).data(), errno); return false; } diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index 5e40a672583d0dbbfb4607be77b1d588084889d6..da37232158a225fd1588bb75581f58a9aac4e813 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -284,9 +284,9 @@ int UntarFile::DealIncreParseTarFileResult(const std::tuple BundleMgrAdapter::GetBundleInfosForIncrement vector bundleNames; vector bundleInfos; - HILOGI("End get installedBundles count is:%{public}zu", installedBundles.size()); + HILOGI("Begin get bundle infos"); for (auto const &installedBundle : installedBundles) { if (installedBundle.applicationInfo.codePath == HMOS_HAP_CODE_PATH || installedBundle.applicationInfo.codePath == LINUX_HAP_CODE_PATH) { @@ -353,8 +353,8 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement GetAllowAndExtName(installedBundle.extensionInfos); if (!allToBackup) { bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.appIndex, - installedBundle.versionCode, installedBundle.versionName, 0, 0, allToBackup, fullBackupOnly, extName, - restoreDeps, supportScene, extraInfo}); + installedBundle.versionCode, installedBundle.versionName, 0, 0, allToBackup, fullBackupOnly, + extName, restoreDeps, supportScene, extraInfo}); continue; } auto it = std::find_if(extraIncreData.begin(), extraIncreData.end(), @@ -385,15 +385,14 @@ vector BundleMgrAdapter::GetFullBundleInfos(int32_t } vector bundleNames; vector bundleInfos; - HILOGI("End get installedBundles count is:%{public}zu", installedBundles.size()); for (auto const &installedBundle : installedBundles) { + HILOGI("Begin get bundle infos, bundleName = %{public}s", installedBundle.name.data()); if (installedBundle.applicationInfo.codePath == HMOS_HAP_CODE_PATH || installedBundle.applicationInfo.codePath == LINUX_HAP_CODE_PATH) { HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); continue; } if (installedBundle.appIndex > 0) { - HILOGI("Current bundle %{public}s is a twin application", installedBundle.name.c_str()); std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(installedBundle.name, installedBundle.appIndex); bundleNames.emplace_back(bundleNameIndexInfo); diff --git a/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp b/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp index 70879196a310d2eff12400e017c4bb4832d96ab4..682b0a2b4ecc6514ba7244c64fa014bf618c17cb 100644 --- a/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp @@ -33,7 +33,7 @@ vector SvcRestoreDepsManager::GetRestoreBundleNames(const vector lock(lock_); if (!impl_.clientToken) { throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); @@ -582,7 +581,7 @@ bool SvcSessionManager::IsOnOnStartSched() if (impl_.isBackupStart && impl_.backupExtNameMap.size()) { return true; } - HILOGI("End"); + return false; } diff --git a/tests/mock/napi/include/napi_mock.h b/tests/mock/napi/include/napi_mock.h index bc699b791d8ba1548bcf6abc11f318245c9546d1..5f70f4f022c00af96c55e54410330bc2f22a0541 100644 --- a/tests/mock/napi/include/napi_mock.h +++ b/tests/mock/napi/include/napi_mock.h @@ -60,6 +60,7 @@ public: virtual napi_status napi_create_function(napi_env, const char*, size_t, napi_callback, void*, napi_value*) = 0; virtual napi_status napi_open_handle_scope(napi_env, napi_handle_scope*) = 0; virtual napi_status napi_close_handle_scope(napi_env, napi_handle_scope) = 0; + virtual napi_status napi_is_exception_pending(napi_env, bool*) = 0; public: static inline std::shared_ptr napi = nullptr; }; @@ -96,6 +97,7 @@ public: MOCK_METHOD6(napi_create_function, napi_status(napi_env, const char*, size_t, napi_callback, void*, napi_value*)); MOCK_METHOD2(napi_open_handle_scope, napi_status(napi_env, napi_handle_scope*)); MOCK_METHOD2(napi_close_handle_scope, napi_status(napi_env, napi_handle_scope)); + MOCK_METHOD2(napi_is_exception_pending, napi_status(napi_env, bool*)); }; } // namespace OHOS::FileManagement::Backup #endif // TEST_UNITTEST_MOCK_NAPI_H \ No newline at end of file diff --git a/tests/mock/napi/src/napi_mock.cpp b/tests/mock/napi/src/napi_mock.cpp index 0310429d36660f0c13e192b167aa541ec70dd138..5b672ce665a256f232ce8cfa4b2bb3360c68aa84 100644 --- a/tests/mock/napi/src/napi_mock.cpp +++ b/tests/mock/napi/src/napi_mock.cpp @@ -18,12 +18,6 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb) { - if (work_cb) { - work_cb(req); - } - if (after_work_cb) { - after_work_cb(req, 0); - } return OHOS::FileManagement::Backup::Napi::napi->uv_queue_work(loop, req, work_cb, after_work_cb); } @@ -163,4 +157,9 @@ NAPI_EXTERN napi_status napi_open_handle_scope(napi_env env, napi_handle_scope* NAPI_EXTERN napi_status napi_close_handle_scope(napi_env env, napi_handle_scope scope) { return OHOS::FileManagement::Backup::Napi::napi->napi_close_handle_scope(env, scope); +} + +napi_status napi_is_exception_pending(napi_env env, bool* result) +{ + return OHOS::FileManagement::Backup::Napi::napi->napi_is_exception_pending(env, result); } \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index e0224ccd38263d306beedca7dfdac38f3d0189d1..21493107959d46e21434d476a5a34b574f424818 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -22,6 +22,7 @@ #include "module_ipc/service.h" #include "service.cpp" #include "service_reverse_mock.h" +#include "sub_service.cpp" #include "test_manager.h" namespace OHOS::FileManagement::Backup { diff --git a/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp b/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp index a09c55ebcb4078fde2d0f056290d2126acc82c6c..239a274bd5d832f0ff427e16b675148c0f5a7598 100644 --- a/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_json_entity_ext_manage_test.cpp @@ -526,6 +526,31 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0803, testing::ext:: GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0803"; } +/** + * @tc.number: SUB_backup_b_json_entity_ext_manage_0804 + * @tc.name: b_json_entity_ext_manage_0804 + * @tc.desc: 测试GetExtManageInfo + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6F3GV + */ +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0804, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0804"; + try { + string_view sv = R"([{"isBigFile":false}, {"fileName":"test"}])"; + BJsonCachedEntity cachedEntity(sv); + auto cache = cachedEntity.Structuralize(); + auto mp = cache.GetExtManageInfo(); + EXPECT_TRUE(mp.empty()); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0804"; +} + /** * @tc.number: SUB_backup_b_json_entity_ext_manage_0900 * @tc.name: b_json_entity_ext_manage_0900 @@ -674,4 +699,32 @@ HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0903, testing::ext:: } GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0903"; } + +/** + * @tc.number: SUB_backup_b_json_entity_ext_manage_0904 + * @tc.name: b_json_entity_ext_manage_0904 + * @tc.desc: 测试CheckOwnPackTar各种异常分支 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issuesI9JXNH + */ +HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0904, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0904"; + try { + string fileName = "/home/user/test.tar"; + auto ret = CheckOwnPackTar(fileName); + EXPECT_FALSE(ret); + + fileName = string(BConstants::PATH_BUNDLE_BACKUP_HOME) + .append(BConstants::SA_BUNDLE_BACKUP_BACKUP).append("/part1.tar"); + ret = CheckOwnPackTar(fileName); + EXPECT_TRUE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0904"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp b/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp index 3e51ac25818a0f48ff46284217bc782764ccb5bf..cbdba7332b544426885262d980bc04c16559f53b 100644 --- a/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp +++ b/tests/unittests/backup_utils/b_json/b_report_entity_test.cpp @@ -227,4 +227,124 @@ HWTEST_F(BReportEntityTest, b_report_entity_DealLine_0100, testing::ext::TestSiz GTEST_LOG_(INFO) << "BReportEntityTest-end b_report_entity_DealLine_0100"; } +/** + * @tc.number: SUB_backup_b_report_entity_DealLine_0101 + * @tc.name: b_report_entity_DealLine_0101 + * @tc.desc: Test function of DealLine interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(BReportEntityTest, b_report_entity_DealLine_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BReportEntityTest-begin b_report_entity_DealLine_0101"; + try { + unordered_map keys; + int num = 1; + string line = ""; + unordered_map infos; + DealLine(keys, num, line, infos); + EXPECT_EQ(infos.size(), 0); + } catch (const exception &e) { + GTEST_LOG_(INFO) << "BReportEntityTest-an exception occurred by DealLine. " << e.what(); + EXPECT_TRUE(false); + } + GTEST_LOG_(INFO) << "BReportEntityTest-end b_report_entity_DealLine_0101"; +} + +/** + * @tc.number: SUB_backup_b_report_entity_StorageDealLine_0100 + * @tc.name: b_report_entity_StorageDealLine_0100 + * @tc.desc: Test function of DealLine interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(BReportEntityTest, b_report_entity_StorageDealLine_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BReportEntityTest-begin b_report_entity_StorageDealLine_0100"; + try { + unordered_map keys; + int num = 1; + string line = ""; + StorageDealLine(keys, num, line); + EXPECT_TRUE(true); + } catch (const exception &e) { + GTEST_LOG_(INFO) << "BReportEntityTest-an exception occurred by DealLine. " << e.what(); + EXPECT_TRUE(false); + } + GTEST_LOG_(INFO) << "BReportEntityTest-end b_report_entity_StorageDealLine_0100"; +} + +/** + * @tc.number: SUB_backup_b_report_entity_StorageDealLine_0101 + * @tc.name: b_report_entity_StorageDealLine_0101 + * @tc.desc: Test function of DealLine interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(BReportEntityTest, b_report_entity_StorageDealLine_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BReportEntityTest-begin b_report_entity_StorageDealLine_0101"; + try { + unordered_map keys; + int num = 0; + string line = "test\r"; + StorageDealLine(keys, num, line); + EXPECT_TRUE(true); + } catch (const exception &e) { + GTEST_LOG_(INFO) << "BReportEntityTest-an exception occurred by DealLine. " << e.what(); + EXPECT_TRUE(false); + } + GTEST_LOG_(INFO) << "BReportEntityTest-end b_report_entity_StorageDealLine_0101"; +} + +/** + * @tc.number: SUB_backup_b_report_entity_StorageDealLine_0102 + * @tc.name: b_report_entity_StorageDealLine_0102 + * @tc.desc: Test function of DealLine interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(BReportEntityTest, b_report_entity_StorageDealLine_0102, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BReportEntityTest-begin b_report_entity_StorageDealLine_0102"; + try { + unordered_map keys; + int num = 1; + string line = "key1;key2;key3"; + StorageDealLine(keys, num, line); + EXPECT_TRUE(true); + } catch (const exception &e) { + GTEST_LOG_(INFO) << "BReportEntityTest-an exception occurred by DealLine. " << e.what(); + EXPECT_TRUE(false); + } + GTEST_LOG_(INFO) << "BReportEntityTest-end b_report_entity_StorageDealLine_0102"; +} + +/** + * @tc.number: SUB_backup_b_report_entity_StorageDealLine_0103 + * @tc.name: b_report_entity_StorageDealLine_0103 + * @tc.desc: Test function of DealLine interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(BReportEntityTest, b_report_entity_StorageDealLine_0103, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BReportEntityTest-begin b_report_entity_StorageDealLine_0103"; + try { + unordered_map keys; + int num = INFO_ALIGN_NUM; + string line = "key1;key2;key3"; + StorageDealLine(keys, num, line); + EXPECT_TRUE(true); + } catch (const exception &e) { + GTEST_LOG_(INFO) << "BReportEntityTest-an exception occurred by DealLine. " << e.what(); + EXPECT_TRUE(false); + } + GTEST_LOG_(INFO) << "BReportEntityTest-end b_report_entity_StorageDealLine_0103"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/utils/include/b_jsonutil/b_jsonutil.h b/utils/include/b_jsonutil/b_jsonutil.h index 0758165801532e06bcdb7359e3d69af6aa063335..37c050a31f1ff8ad7429d2a0c358d5420244d324 100644 --- a/utils/include/b_jsonutil/b_jsonutil.h +++ b/utils/include/b_jsonutil/b_jsonutil.h @@ -96,17 +96,7 @@ public: */ static bool BuildExtensionErrInfo(std::string &jsonStr, int errCode, std::string errMsg); - /** - * @brief 拼接包名和分身对应的索引 - * - * @param bundleName 包名 - * @param bundleIndex 索引 - * - * @return 拼接结果 - */ - static std::string BuildBundleNameIndexInfo(const std::string &bundleName, int bundleIndex); - - /** + /* * * @brief 组建恢复文件错误信息的json * * @param jsonStr 组建结果 @@ -117,9 +107,8 @@ public: */ static bool BuildExtensionErrInfo(std::string &jsonStr, std::map> errFileInfo); - /** + /* * * @brief 组建App进度返回的信息 - * * @param jsonStr 组建结果 * @param onProcessRet onProcess接口返回值 * @@ -128,6 +117,15 @@ public: */ static bool BuildOnProcessRetInfo(std::string &jsonStr, std::string onProcessRet); + /* * + * @brief 拼接包名和分身对应的索引 + * + * @param bundleName 包名 + * @param bundleIndex 索引 + * + * @return 拼接结果 + */ + static std::string BuildBundleNameIndexInfo(const std::string &bundleName, int bundleIndex); /** * @brief 组建App进度返回的信息 * diff --git a/utils/src/b_jsonutil/b_jsonutil.cpp b/utils/src/b_jsonutil/b_jsonutil.cpp index f3e55f4f14a24599ecca13e2df766c27996ed290..751054b9a6c0a685d914be3da6b1d6f9a3beaa7c 100644 --- a/utils/src/b_jsonutil/b_jsonutil.cpp +++ b/utils/src/b_jsonutil/b_jsonutil.cpp @@ -167,13 +167,11 @@ bool BJsonUtil::HasUnicastInfo(std::string &bundleInfo) cJSON *infoItem = cJSON_GetArrayItem(infos, i); if (!cJSON_IsObject(infoItem)) { HILOGE("Parse json error, info item is not an object"); - cJSON_Delete(root); continue; } cJSON *type = cJSON_GetObjectItem(infoItem, "type"); if (type == nullptr || !cJSON_IsString(type) || (type->valuestring == nullptr)) { HILOGE("Parse json type element error"); - cJSON_Delete(root); continue; } if (string(type->valuestring).compare(BConstants::UNICAST_TYPE) == 0) { @@ -306,17 +304,6 @@ bool BJsonUtil::BuildExtensionErrInfo(std::string &jsonStr, int errCode, std::st return true; } -std::string BJsonUtil::BuildBundleNameIndexInfo(const std::string &bundleName, int appIndex) -{ - std::string result = bundleName; - if (appIndex == BUNDLE_INDEX_DEFAULT_VAL) { - return result; - } - result += BUNDLE_INDEX_SPLICE; - result += std::to_string(appIndex); - return result; -} - bool BJsonUtil::BuildExtensionErrInfo(std::string &jsonStr, std::map> errFileInfo) { cJSON *errJson = cJSON_CreateObject(); @@ -353,7 +340,6 @@ bool BJsonUtil::BuildExtensionErrInfo(std::string &jsonStr, std::map