diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h index 8405b9b88aa67fa16d707b336eb6ca0a2e902dcb..fc705c6f63a2996afbae716e4c8405fe689dbeac 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h @@ -79,12 +79,15 @@ public: * * @param remoteCap 已打开的保存远端设备能力的Json文件。可使用GetLocalCapabilities方法获取 * @param bundlesToRestore 待恢复的应用清单 + * @param detailInfos bundle的单双映射关系json串 * @param userId 用户ID * @return ErrCode 规范错误码 - */ - ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore, - std::vector detailInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, - int32_t userId = DEFAULT_INVAL_VALUE); + */ + ErrCode AppendBundles(UniqueFd remoteCap, + std::vector bundlesToRestore, + std::vector detailInfos, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); /** * @brief 用于追加待恢复应用 diff --git a/interfaces/innerkits/native/file_uri/include/file_uri.h b/interfaces/innerkits/native/file_uri/include/file_uri.h index 1f8f50410c7bbeebf2718b2df408b00983d10b69..8ae2f8a114b322a817a8ad53329be7b331e698d0 100644 --- a/interfaces/innerkits/native/file_uri/include/file_uri.h +++ b/interfaces/innerkits/native/file_uri/include/file_uri.h @@ -26,8 +26,8 @@ class FileUri { public: std::string GetName(); std::string GetPath(); - std::string GetRealPathBySA(const std::string &targetBundleName = ""); std::string GetRealPath(); + std::string GetRealPathBySA(const std::string &targetBundleName = ""); std::string ToString(); std::string GetFullDirectoryUri(); bool IsRemoteUri(); diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index 80edd1a771ae3a57210318537f1c5dc8169e198a..1f6f5d7b01b88763fd0a050da24d930608f0a045 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -247,35 +247,35 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info return nResult; } -bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeout) +bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) { bool result = false; ServiceProxy::InvaildInstance(); auto proxy = ServiceProxy::GetInstance(); if (!proxy) { - HILOGE("called DoUpdateTimer,failed to get proxy"); + HILOGE("called UpdateSendRate,failed to get proxy"); return result; } - ErrCode errcode = proxy->UpdateTimer(bundleName, timeout, result); - if (errcode != 0) { - HILOGE("proxy->UpdateTimer faild."); + ErrCode errCode = proxy->UpdateSendRate(bundleName, sendRate, result); + if (errCode != 0) { + HILOGE("Proxy execute UpdateSendRate failed. errCode:%{public}d", errCode); return result; } return result; } -bool PropNOperation::UpdateSendRate(std::string &bundleName, int32_t sendRate) +bool PropNOperation::UpdateTimer(std::string &bundleName, uint32_t timeout) { bool result = false; ServiceProxy::InvaildInstance(); auto proxy = ServiceProxy::GetInstance(); if (!proxy) { - HILOGE("called UpdateSendRate,failed to get proxy"); + HILOGE("called DoUpdateTimer,failed to get proxy"); return result; } - ErrCode errCode = proxy->UpdateSendRate(bundleName, sendRate, result); - if (errCode != 0) { - HILOGE("Proxy execute UpdateSendRate failed. errCode:%{public}d", errCode); + ErrCode errcode = proxy->UpdateTimer(bundleName, timeout, result); + if (errcode != 0) { + HILOGE("proxy->UpdateTimer faild."); return result; } return result; @@ -309,7 +309,7 @@ napi_value PropNOperation::DoUpdateTimer(napi_env env, napi_callback_info info) } NVal jsBundleInt(env, funcArg[NARG_POS::SECOND]); auto [succInt, time] = jsBundleInt.ToInt32(); - if (!succInt || time <= 0 || time > static_cast(BConstants::MAX_UPDATE_TIMER)) { + if (!succInt || time < 0 || time > static_cast(BConstants::MAX_UPDATE_TIMER)) { HILOGE("Second argument is not number."); NError(E_PARAMS).ThrowErr(env); return nullptr; @@ -378,4 +378,4 @@ napi_value PropNOperation::DoUpdateSendRate(napi_env env, napi_callback_info inf HILOGI("DoUpdateSendRate success with result: %{public}d", result); return nResult; } -} // namespace OHOS::FileManagement::Backup \ No newline at end of file +} // namespace OHOS::FileManagement::Backup diff --git a/test/unittest/file_share_native/file_share_test.cpp b/test/unittest/file_share_native/file_share_test.cpp index dea3a408a889cb8fa84c0f756442c9f605cc9ea4..2cd55d06f1b89b62f0aeac7ebe47076cce8be7ad 100644 --- a/test/unittest/file_share_native/file_share_test.cpp +++ b/test/unittest/file_share_native/file_share_test.cpp @@ -25,7 +25,6 @@ #include "access_token_error.h" #include "accesstoken_kit.h" -#include "file_permission.h" #include "file_share.h" #include "ipc_skeleton.h" #include "log.h" diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index 09f229ea3b7bc985535e970e9a16080067453ebd..04c6afe8ab0e7ee00b766e554c18c1883139c1d9 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -86,14 +86,17 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } -ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + RestoreTypeEnum restoreType, + int32_t userId) { return BError(BError::Codes::OK); } ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, + const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) { diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 9b86753cfdfde9e9a90bdf45acab6f108d80bd6d..07ae3a29230ab8d379044438aa57746c3d351ab1 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -40,8 +40,6 @@ ServiceStub::ServiceStub() opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_PUBLISH_FILE)] = &ServiceStub::CmdPublishFile; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APP_DONE)] = &ServiceStub::CmdAppDone; - opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_RESULT_REPORT)] = - &ServiceStub::CmdResultReport; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START)] = &ServiceStub::CmdStart; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_FILE_NAME)] = &ServiceStub::CmdGetFileHandle; @@ -190,6 +188,7 @@ int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, Message UniqueFd fd(data.ReadFileDescriptor()); std::vector bundleNames; data.ReadStringVector(&bundleNames); + int res = AppendBundlesRestoreSession(move(fd), bundleNames); reply.WriteInt32(res); return BError(BError::Codes::OK); @@ -211,6 +210,7 @@ int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageP { std::vector bundleNames; data.ReadStringVector(&bundleNames); + int res = AppendBundlesBackupSession(bundleNames); reply.WriteInt32(res); return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index ec2a2867f161d07687a5110db764a1564a6ba81f..a0da61edc9fc132789a051c9f64d6a9cb84218a6 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -102,6 +102,7 @@ public: ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, + const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) override { @@ -110,7 +111,6 @@ public: ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) override { diff --git a/tests/unittests/backup_ext/BUILD.gn b/tests/unittests/backup_ext/BUILD.gn index a565d18ca69ef37dc00e652e4096068dd597c0b2..849943f247ed548a33f3bb94ee35e90ac2cec557 100644 --- a/tests/unittests/backup_ext/BUILD.gn +++ b/tests/unittests/backup_ext/BUILD.gn @@ -193,6 +193,82 @@ ohos_unittest("tar_file_test") { use_exceptions = true } +ohos_unittest("untar_file_sup_test") { + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "${path_backup}/cfi_blocklist.txt" + } + + module_out_path = path_module_out_tests + + sources = [ + "${path_backup}/frameworks/native/backup_ext/src/ext_backup.cpp", + "${path_backup}/frameworks/native/backup_ext/src/ext_backup_context.cpp", + "${path_backup}/frameworks/native/backup_ext/src/ext_backup_context_js.cpp", + "${path_backup}/frameworks/native/backup_ext/src/ext_backup_js.cpp", + "${path_backup}/frameworks/native/backup_ext/src/ext_backup_loader.cpp", + "${path_backup}/frameworks/native/backup_ext/src/ext_extension.cpp", + "${path_backup}/frameworks/native/backup_ext/src/ext_extension_stub.cpp", + "${path_backup}/frameworks/native/backup_ext/src/sub_ext_extension.cpp", + "${path_backup}/frameworks/native/backup_ext/src/tar_file.cpp", + "${path_backup}/tests/mock/library_func_mock/library_func_mock.cpp", + "untar_file_sup_test.cpp", + ] + sources += backup_mock_proxy_src + + include_dirs = [ + "${path_ability_runtime}/services/common/include", + "${path_ability_runtime}/interfaces/kits/napi/aafwk/inner/napi_common", + "${path_ability_runtime}/interfaces/kits/native/appkit/ability_runtime", + "${path_backup}/frameworks/native/backup_ext/include", + "${path_backup}/frameworks/native/backup_ext/src", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/frameworks/native/backup_kit_inner/include", + "${path_backup}/tests/mock/library_func_mock", + "${path_backup}/utils/include", + "${path_napi}/native_engine", + ] + include_dirs += backup_mock_utils_include + + deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", + "${path_backup}/tests/utils:backup_test_utils", + "${path_backup}/utils:backup_utils", + "${path_googletest}:gmock_main", + "${path_jsoncpp}:jsoncpp", + ] + + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + cflags_cc = [ "--coverage" ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "ability_runtime:app_context", + "ability_runtime:appkit_native", + "ability_runtime:runtime", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "samgr:samgr_proxy", + ] + + defines = [ "private=public" ] + + use_exceptions = true +} + ohos_unittest("untar_file_test") { branch_protector_ret = "pac_ret" sanitize = { @@ -327,12 +403,14 @@ ohos_unittest("ext_backup_js_test") { group("backup_ext_test") { testonly = true - - deps = [ - ":ext_backup_js_test", - ":ext_extension_stub_test", - ":ext_extension_test", - ":tar_file_test", - ":untar_file_test", - ] + if (!use_libfuzzer) { + deps = [ + ":ext_backup_js_test", + ":ext_extension_stub_test", + ":ext_extension_test", + ":tar_file_test", + ":untar_file_sup_test", + ":untar_file_test", + ] + } } diff --git a/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp b/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp index fc93f542ff066a40012f593fdd5117bbdf1e2f1e..531a634068daea86216edfda91281b66399674f2 100644 --- a/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp +++ b/tests/unittests/backup_utils/b_filesystem/b_dir_test.cpp @@ -24,6 +24,7 @@ #include #include "b_filesystem/b_dir.h" +#include "b_dir.cpp" #include "b_process/b_process.h" #include "test_manager.h" @@ -318,4 +319,28 @@ HWTEST_F(BDirTest, b_dir_GetDirs_0100, testing::ext::TestSize.Level1) GTEST_LOG_(INFO) << "BDirTest-end b_dir_GetDirs_0100"; } +/** + * @tc.number: SUB_backup_b_dir_GetFile_0100 + * @tc.name: b_dir_GetFile_0100 + * @tc.desc: Test function of GetFile interface for SUCCESS + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(BDirTest, b_dir_GetFile_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BDirTest-begin b_dir_GetFile_0100"; + try { + string path = "/"; + auto [errCode, subFiles, subSmallFiles] = GetFile(path); + string pathData = "/data"; + auto [errCode1, subFiles1, subSmallFiles1] = GetFile(pathData, PATH_MAX_LEN); + auto [errCode2, subFiles2, subSmallFiles2] = GetFile(pathData); + EXPECT_EQ(errCode, 0); + } catch (...) { + GTEST_LOG_(INFO) << "BDirTest-an exception occurred."; + } + GTEST_LOG_(INFO) << "BDirTest-end b_dir_GetFile_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp b/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp index a0f8621a8dc4d1c4ec672f0cdd7c6376339f5b66..bedfa2e60bd566005d67345090e3cd916e1a411a 100644 --- a/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp +++ b/tests/unittests/backup_utils/b_filesystem/b_file_hash_test.cpp @@ -74,4 +74,26 @@ HWTEST_F(BFileHashTest, b_file_hash_HashWithSHA256_0100, testing::ext::TestSize. } GTEST_LOG_(INFO) << "BFileHashTest-end b_file_hash_HashWithSHA256_0100"; } + +/** + * @tc.number: SUB_backup_b_file_hash_HashWithSHA256_0101 + * @tc.name: b_file_hash_HashWithSHA256_0100 + * @tc.desc: Test function of HashWithSHA256 interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(BFileHashTest, b_file_hash_HashWithSHA256_0101, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "BFileHashTest-begin b_file_hash_HashWithSHA256_0101"; + try { + std::string filePath = "/errPath"; + auto [res, fileHash] = BackupFileHash::HashWithSHA256(filePath); + EXPECT_NE(res, 0); + } catch (const exception &e) { + GTEST_LOG_(INFO) << "BFileHashTest-an exception occurred by HashWithSHA256."; + e.what(); + } + GTEST_LOG_(INFO) << "BFileHashTest-end b_file_hash_HashWithSHA256_0101"; +} } // 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