From 5bf7a2965b741d1a1acacad269b34328a8eac2ff Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 8 Apr 2025 14:10:06 +0800 Subject: [PATCH 1/4] add ut for coverage. Signed-off-by: BrainL --- tests/unittests/backup_sa/BUILD.gn | 1 + .../backup_sa/module_client/BUILD.gn | 86 +++ .../module_client/service_client_test.cpp | 425 ++++++++++++ .../backup_sa/module_client/service_mock.cpp | 626 ++++++++++++++++++ 4 files changed, 1138 insertions(+) create mode 100644 tests/unittests/backup_sa/module_client/BUILD.gn create mode 100644 tests/unittests/backup_sa/module_client/service_client_test.cpp create mode 100644 tests/unittests/backup_sa/module_client/service_mock.cpp diff --git a/tests/unittests/backup_sa/BUILD.gn b/tests/unittests/backup_sa/BUILD.gn index 5351c84bd..b552944b3 100644 --- a/tests/unittests/backup_sa/BUILD.gn +++ b/tests/unittests/backup_sa/BUILD.gn @@ -19,6 +19,7 @@ group("backup_sa_test") { deps = [ "module_app_gallery:app_gallery_test", + "module_client:service_client_test", "module_external:adapter_test", "module_ipc:backup_sa_ipc_test", "session:session_test", diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn new file mode 100644 index 000000000..47a26fff8 --- /dev/null +++ b/tests/unittests/backup_sa/module_client/BUILD.gn @@ -0,0 +1,86 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") +import("//foundation/filemanagement/app_file_service/backup.gni") + +ohos_unittest("service_client_test") { + module_out_path = path_module_out_tests + + include_dirs = [ + "${path_backup}/frameworks/native/backup_kit_inner/include", + "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", + "${path_backup}/services/backup_sa/include", + "${path_backup}/services/backup_sa/include/module_notify", + "${path_backup}/utils/include", + "${path_backup}/utils/src", + "${path_backup}/tests/mock/utils_mock/include", + ".", + ] + + sources = [ + "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", + "service_client_test.cpp", + ] + + deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/services/backup_sa:backup_sa_ipc_stub", + "${path_backup}/utils:backup_utils", + ] + + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + + defines = [ + "LOG_TAG=\"app_file_service\"", + "LOG_DOMAIN=0xD200000", + "private = public", + "protected = public", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_connect_callback_stub", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "storage_service:storage_manager_sa_proxy", + ] + + use_exceptions = true +} + +group("backup_sa_service_client_test") { + testonly = true + deps = [ ":service_client_test" ] +} diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp new file mode 100644 index 000000000..e9ba7c350 --- /dev/null +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +#include "b_error/b_error.h" +#include "service_client.h" +#include "service_reverse.h" +#include "b_session_restore.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; +using namespace testing; + +class ServiceClientTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(); + void SetUp() override {}; + void TearDown() override {}; + +public: + static inline sptr proxy = nullptr; +}; + +void ServiceClientTest::SetUpTestCase() +{ + GTEST_LOG_(INFO) << "begin SetUpTestCase"; + proxy = ServiceClient::GetInstance(); + if (proxy == nullptr) { + GTEST_LOG_(INFO) << "Failed to get ServiceClient instance"; + } +} + +void ServiceClientTest::TearDownTestCase() +{ + if (proxy != nullptr) { + ServiceClient::InvaildInstance(); + proxy = nullptr; + } + ServiceClient::InvaildInstance(); +} + +/** + * @tc.number: SUB_service_client_test_0100 + * @tc.name: SUB_service_client_test_0100 + * @tc.desc: 测试 InitIncrementalBackupSession 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: issuesI9KPRL + */ +HWTEST_F(ServiceClientTest, SUB_service_client_test_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0100"; + EXPECT_NE(proxy, nullptr); + ServiceClient::InvaildInstance(); + proxy=ServiceClient::serviceProxy_; + EXPECT_EQ(proxy, nullptr); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0100"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0200"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode ret = proxy->Start(); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->Finish(); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->Release(); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_PERM)); + ret = proxy->GetAppLocalListAndDoIncrementalBackup(); + EXPECT_NE(ret, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0200"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0300"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + int32_t result = -1; + ErrCode ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + bundleName = ""; + ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + bundleName = "test"; + ret = proxy->Cancel(bundleName, result); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CANCEL_UNSTARTED_TASK)); + EXPECT_NE(result, 0); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0300"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0400"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode err = -1; + ErrCode ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 0; + ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 1; + ret = proxy->AppIncrementalDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0400"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0500"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + ErrCode err = -1; + ErrCode ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 0; + ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + err = 1; + ret = proxy->AppDone(err); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0500"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0600, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0600"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + int fd = -1; + ErrCode ret = proxy->GetLocalCapabilities(fd); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + fd = -2; + ret = proxy->GetLocalCapabilitiesForBundleInfos(fd); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0600"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0700, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0700"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + std::string fileName; + ErrCode ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + fileName = ""; + ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = "test"; + fileName = "test"; + ret = proxy->GetIncrementalFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0700"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0800"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + std::string fileName; + bool booleanValue = false; + ErrCode ret = proxy->GetBackupInfo(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_BEF)); + EXPECT_EQ(bundleName, ""); + EXPECT_EQ(fileName, ""); + booleanValue = true; + ret = proxy->StartExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StartExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + booleanValue = true; + ret = proxy->StartFwkTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StartFwkTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + booleanValue = true; + ret = proxy->StopExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + booleanValue = false; + ret = proxy->StopExtTimer(booleanValue); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bool isExt = true; + bundleName = ""; + ret = proxy->UpdateTimer(bundleName, 0, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(isExt, false); + bundleName = ""; + ret = proxy->UpdateTimer(bundleName, 0, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(isExt, false); + bundleName = "test"; + ret = proxy->UpdateTimer(bundleName, 10, isExt); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(isExt, false); + + isExt = true; + bundleName = ""; + ret = proxy->UpdateSendRate(bundleName, 0, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + + isExt = true; + bundleName = ""; + ret = proxy->UpdateSendRate(bundleName, 0, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + + bundleName = "test"; + ret = proxy->UpdateSendRate(bundleName, 10, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + bundleName = ""; + ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = "test"; + ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = ""; + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = ""; + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = "name"; + ret = proxy->AppFileReady(fileName, -1, 0); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + fileName = ""; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + bundleName = ""; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + bundleName = "test"; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0800"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_0900, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0900"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string stringVal = ""; + ErrCode ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = ""; + ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = "test"; + ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + int64_t val = -1; + ret = proxy->RefreshDataSize(val); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + val = 1; + ret = proxy->RefreshDataSize(val); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = ""; + ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + stringVal = ""; + ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0900"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1000, testing::ext::TestSize.Level1) +{ + std::string bundleName = ""; + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1000"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + BFileInfo *fileInfo = nullptr; + BFileInfo bf {bundleName, "", 0}; + fileInfo = &bf; + ErrCode ret = proxy->PublishFile(*fileInfo); + EXPECT_NE(ret, BError(BError::Codes::OK)); + ret = proxy->PublishIncrementalFile(*fileInfo); + EXPECT_NE(ret, BError(BError::Codes::OK)); + ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); + EXPECT_NE(ret, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1000"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1100"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + int fd = 0; + int32_t restoreType = -1; + int32_t userid = -1; + std::vector bundleNames; + std::vector detailInfos; + std::vector bundlesToBackup; + ErrCode ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesBackupSession(bundleNames); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleNames.push_back("test"); + ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesBackupSession(bundleNames); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + detailInfos.push_back("test"); + ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + restoreType = 1; + userid = 1; + ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1100"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1200"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + sptr srptr = nullptr; + ErrCode ret = proxy->InitRestoreSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + std::string errMsg = ""; + std::string result = "err"; + ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + BSessionRestore::Callbacks callback; + srptr = sptr(new ServiceReverse(callback)); + ret = proxy->InitRestoreSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->InitIncrementalBackupSession(srptr); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + + ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(errMsg, ""); + + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; +} + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1300"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1300"; +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_client/service_mock.cpp b/tests/unittests/backup_sa/module_client/service_mock.cpp new file mode 100644 index 000000000..2ff375bb1 --- /dev/null +++ b/tests/unittests/backup_sa/module_client/service_mock.cpp @@ -0,0 +1,626 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "module_ipc/service.h" + +#include +#include +#include +#include + +#include "b_error/b_error.h" +#include "b_resources/b_constants.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +int32_t Service::GetUserIdDefault() +{ + return 0; +} + +void Service::OnStart() {} + +void Service::OnStop() {} + +ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) +{ + fd = 1; + return BError(BError::Codes::OK); +} +ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + errMsg = "err"; + return BError(BError::Codes::OK); +} + +ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) +{ + if (reverseIpcRemoteObject == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + errMsg = "err"; + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + int32_t restoreType, + int32_t userId) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (detailInfos.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (restoreType < 0 || userId < 0 || fd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSessionData(int fd, + const std::vector &bundleNames, + int32_t restoreType, + int32_t userId) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (restoreType < 0 || userId < 0 || fd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} +ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( + const std::vector &bundlesToBackup, + const std::vector &bundleInfos) +{ + if (bundlesToBackup.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (bundleInfos.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::GetLocalCapabilities(int &fd) +{ + fd = 1; + return BError(BError::Codes::OK); +} + +UniqueFd Service::GetLocalCapabilities() +{ + return UniqueFd(-1); +} + +UniqueFd Service::GetLocalCapabilitiesForBundleInfos() +{ + return UniqueFd(-1); +} + +void Service::StopAll(const wptr &obj, bool force) {} + +ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::InitRestoreSession(const sptr &remote) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::InitBackupSession(const sptr &remote) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::Start() +{ + GTEST_LOG_(INFO) << "Service mock start"; + return BError(BError::Codes::OK); +} + +ErrCode Service::PublishFile(const BFileInfo &fileInfo) +{ + if (fileInfo.fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) +{ + if (fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (fd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppDone(ErrCode errCode) +{ + if (errCode == 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (errCode == -1) { + return BError(BError::BackupErrorCode::E_EMPTY); + } + if (errCode > 0) { + return BError(BError::Codes::OK); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) +{ + if (restoreRetInfo.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + const std::vector &detailInfos, + RestoreTypeEnum restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType, + int32_t userId) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, + const std::vector &bundleInfos) +{ + if (bundleNames.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (bundleInfos.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::Finish() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +void Service::OnBackupExtensionDied(const string &&bundleName, bool isCleanCalled) {} + +void Service::ExtConnectDied(const string &callName) {} + +void Service::ExtStart(const string &bundleName) {} + +int Service::Dump(int fd, const vector &args) +{ + return 0; +} + +void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) +{ + GTEST_LOG_(INFO) << "ExtConnectFailed is OK"; +} + +void Service::ExtConnectDone(string bundleName) {} + +void Service::ClearSessionAndSchedInfo(const string &bundleName) {} + +ErrCode Service::VerifyCaller() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) +{ + return BError(BError::Codes::OK); +} + +void Service::OnAllBundlesFinished(ErrCode errCode) {} + +void Service::OnStartSched() {} + +void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} + +void Service::SessionDeactive() {} + +ErrCode Service::Release() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (!bundleName.empty()) { + result = 0; + return BError(BError::Codes::OK); + } + result = BError(BError::Codes::OK); + return BError(BError::Codes::OK); +} + +ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) +{ + fd = 1; + return BError(BError::Codes::OK); +} + +ErrCode Service::GetAppLocalListAndDoIncrementalBackup() +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::InitIncrementalBackupSession(const sptr &remote) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) +{ + if (remote == nullptr) { + return BError(BError::Codes::SA_BROKEN_IPC); + } + errMsg = "err"; + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, + const std::vector &infos) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) +{ + if (fileInfo.fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) +{ + if (fileInfo.fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::AppIncrementalFileReady(const std::string &fileName, + int fd, + int manifestFd, + int32_t appIncrementalFileReadyErrCode) +{ + if (fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (fd < 0 || manifestFd < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + + return BError(BError::Codes::OK); +} + +ErrCode Service::AppIncrementalDone(ErrCode errCode) +{ + if (errCode == 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (errCode == -1) { + return BError(BError::BackupErrorCode::E_EMPTY); + } + if (errCode > 0) { + return BError(BError::Codes::OK); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string &fileName) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + if (fileName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) +{ + bundleName = "name"; + result = "abc"; + return BError(BError::Codes::OK); +} + +ErrCode Service::StartExtTimer(bool &isExtStart) +{ + if (isExtStart) { + return BError(BError::Codes::OK); + } + + return BError(BError::BackupErrorCode::E_TASKFAIL); +} + +ErrCode Service::StartFwkTimer(bool &isFwkStart) +{ + if (isFwkStart) { + return BError(BError::Codes::OK); + } + + return BError(BError::BackupErrorCode::E_TASKFAIL); +} + +ErrCode Service::StopExtTimer(bool &isExtStop) +{ + if (isExtStop) { + return BError(BError::Codes::OK); + } + return BError(BError::BackupErrorCode::E_TASKFAIL); +} + +ErrCode Service::RefreshDataSize(int64_t totalDatasize) +{ + if (totalDatasize < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + if (timeout < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + result = true; + return BError(BError::Codes::OK); +} + +ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) +{ + if (bundleName.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + if (sendRate < 0) { + return BError(BError::BackupErrorCode::E_INVAL); + result = false; + } + result = true; + return BError(BError::Codes::OK); +} + +ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) +{ + if (processInfo.empty()) { + return BError(BError::BackupErrorCode::E_INVAL); + } + return BError(BError::Codes::OK); +} + +void Service::OnSABackup(const std::string &bundleName, + const int &fd, + const std::string &result, + const ErrCode &errCode) +{ +} + +void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {} + +ErrCode Service::ClearResidualBundleData(const std::string &bundleName) +{ + return BError(BError::Codes::OK); +} + +std::shared_ptr Service::GetExtensionMutex(const BundleName &bundleName) +{ + return make_shared(bundleName); +} + +void Service::RemoveExtensionMutex(const BundleName &bundleName) {} + +void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} + +void Service::HandleExceptionOnAppendBundles(sptr session, + const vector &appendBundleNames, + const vector &restoreBundleNames) +{ +} + +void Service::BundleBeginRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::BundleEndRadarReport(const std::string &bundleName, + ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::FileReadyRadarReport(const std::string &bundleName, + const std::string &fileName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, + const ErrCode errCode, + const IServiceReverseType::Scenario scenario) +{ +} + +void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} + +void Service::OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage) {} + +std::string Service::GetCallerName() +{ + return ""; +} + +bool Service::IsReportBundleExecFail(const std::string &bundleName) +{ + return true; +} + +void Service::ClearBundleRadarReport() {} + +void Service::UpdateBundleRadarReport(const std::string &bundleName) {} + +bool Service::IsReportFileReadyFail(const std::string &bundleName) +{ + return true; +} + +void Service::ClearFileReadyRadarReport() {} + +void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {} + +void Service::ClearFailedBundles() {} + +void Service::GetOldDeviceBackupVersion() {} + +void Service::CreateDirIfNotExist(const std::string &path) {} + +void Service::StartRunningTimer(const std::string &bundleName) {} + +std::vector Service::GetSupportBackupBundleNames(vector &, + bool, + const vector &) +{ + return {}; +} + +void Service::HandleNotSupportBundleNames(const vector &, vector &, bool) {} + +void Service::SetBundleIncDataInfo(const std::vector &, std::vector &) {} + +void Service::CancelTask(std::string bundleName, wptr ptr) {} + +void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} + +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ +} + +void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} + +ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) +{ + return BError(BError::Codes::OK); +} + +void Service::GetDataSizeStepByStep(bool isPreciseScan, vector bundleNameList, string &scanning) {} + +void Service::GetPresumablySize(vector bundleNameList, string &scanning) {} + +void Service::GetPrecisesSize(vector bundleNameList, string &scanning) {} + +void Service::WriteToList(BJsonUtil::BundleDataSize bundleDataSize) {} + +void Service::DeleteFromList(size_t scannedSize) {} + +void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {} + +void Service::SendScannedInfo(const string &scannendInfos, sptr session) {} + +void Service::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} + +bool Service::GetScanningInfo(wptr obj, size_t scannedSize, string &scanning) +{ + return true; +} + +void Service::SetScanningInfo(string &scanning, string name) {} +} // namespace OHOS::FileManagement::Backup -- Gitee From ebe08ecd2e879ae75351b607ef2ebca3b45ea3e5 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 8 Apr 2025 14:54:14 +0800 Subject: [PATCH 2/4] code check modify. Signed-off-by: BrainL --- .../module_client/service_client_test.cpp | 100 ++++++++---------- 1 file changed, 43 insertions(+), 57 deletions(-) diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index e9ba7c350..5106f06e6 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -193,14 +193,12 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize booleanValue = false; ret = proxy->StartExtTimer(booleanValue); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = true; ret = proxy->StartFwkTimer(booleanValue); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); booleanValue = false; ret = proxy->StartFwkTimer(booleanValue); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = true; ret = proxy->StopExtTimer(booleanValue); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); @@ -210,66 +208,12 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize bool isExt = true; bundleName = ""; ret = proxy->UpdateTimer(bundleName, 0, isExt); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_EQ(isExt, false); - bundleName = ""; - ret = proxy->UpdateTimer(bundleName, 0, isExt); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); EXPECT_EQ(isExt, false); bundleName = "test"; ret = proxy->UpdateTimer(bundleName, 10, isExt); EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_EQ(isExt, false); - - isExt = true; - bundleName = ""; - ret = proxy->UpdateSendRate(bundleName, 0, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_TRUE(isExt); - - isExt = true; - bundleName = ""; - ret = proxy->UpdateSendRate(bundleName, 0, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_TRUE(isExt); - - bundleName = "test"; - ret = proxy->UpdateSendRate(bundleName, 10, isExt); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_TRUE(isExt); - bundleName = ""; - ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = ""; - ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = "test"; - ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - fileName = ""; - ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - fileName = ""; - ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - fileName = "name"; - ret = proxy->AppFileReady(fileName, -1, 0); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = ""; - fileName = ""; - ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(fileName, ""); - bundleName = ""; - ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(fileName, ""); - bundleName = "test"; - ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(fileName, ""); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0800"; } @@ -422,4 +366,46 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1300, testing::ext::TestSize GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1300"; } + +HWTEST_F(ServiceClientTest, SUB_service_client_test_1400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1400"; + proxy = ServiceClient::GetInstance(); + EXPECT_NE(proxy, nullptr); + std::string bundleName; + std::string fileName; + bool isExt = true; + bundleName = ""; + ret = proxy->UpdateSendRate(bundleName, 0, isExt); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + bundleName = "test"; + ret = proxy->UpdateSendRate(bundleName, 10, isExt); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_TRUE(isExt); + bundleName = ""; + ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = "test"; + ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = ""; + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + fileName = "name"; + ret = proxy->AppFileReady(fileName, -1, 0); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + ret = proxy->AppFileReady(fileName, 0, 0); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + bundleName = ""; + fileName = ""; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_NE(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + bundleName = "test"; + ret = proxy->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_EQ(fileName, ""); + GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1400"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 7a9c59bb058555dcc7d2d5218ec52006a22a7728 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 8 Apr 2025 15:28:02 +0800 Subject: [PATCH 3/4] fixed unit test. Signed-off-by: BrainL --- tests/unittests/backup_sa/module_client/service_client_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index 5106f06e6..539471ff5 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -376,7 +376,7 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1400, testing::ext::TestSize std::string fileName; bool isExt = true; bundleName = ""; - ret = proxy->UpdateSendRate(bundleName, 0, isExt); + ErrCode ret = proxy->UpdateSendRate(bundleName, 0, isExt); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); EXPECT_TRUE(isExt); bundleName = "test"; -- Gitee From 46f73ae803bbec24f4881be669e78fd6d1cf91a1 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 8 Apr 2025 21:28:03 +0800 Subject: [PATCH 4/4] Fixed unit test. Signed-off-by: BrainL --- .../module_client/service_client_test.cpp | 54 +- .../backup_sa/module_client/service_mock.cpp | 626 ------------------ 2 files changed, 27 insertions(+), 653 deletions(-) delete mode 100644 tests/unittests/backup_sa/module_client/service_mock.cpp diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp index 539471ff5..0cecf86a5 100644 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ b/tests/unittests/backup_sa/module_client/service_client_test.cpp @@ -208,7 +208,7 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize bool isExt = true; bundleName = ""; ret = proxy->UpdateTimer(bundleName, 0, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); EXPECT_EQ(isExt, false); bundleName = "test"; ret = proxy->UpdateTimer(bundleName, 10, isExt); @@ -276,9 +276,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize std::vector detailInfos; std::vector bundlesToBackup; ErrCode ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppendBundlesBackupSession(bundleNames); @@ -287,9 +287,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); bundleNames.push_back("test"); ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppendBundlesBackupSession(bundleNames); @@ -298,9 +298,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); detailInfos.push_back("test"); ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); @@ -308,9 +308,9 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize restoreType = 1; userid = 1; ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1100"; @@ -323,36 +323,36 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize EXPECT_NE(proxy, nullptr); sptr srptr = nullptr; ErrCode ret = proxy->InitRestoreSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->InitBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->InitIncrementalBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); std::string errMsg = ""; std::string result = "err"; ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); BSessionRestore::Callbacks callback; srptr = sptr(new ServiceReverse(callback)); ret = proxy->InitRestoreSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::Codes::OK)); ret = proxy->InitBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); ret = proxy->InitIncrementalBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); ret = proxy->InitRestoreSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); EXPECT_EQ(errMsg, ""); ret = proxy->InitBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); EXPECT_EQ(errMsg, ""); ret = proxy->InitIncrementalBackupSessionWithErrMsg(srptr, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); EXPECT_EQ(errMsg, ""); GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; @@ -381,26 +381,26 @@ HWTEST_F(ServiceClientTest, SUB_service_client_test_1400, testing::ext::TestSize EXPECT_TRUE(isExt); bundleName = "test"; ret = proxy->UpdateSendRate(bundleName, 10, isExt); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); EXPECT_TRUE(isExt); bundleName = ""; ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); bundleName = "test"; ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); fileName = ""; ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); fileName = "name"; ret = proxy->AppFileReady(fileName, -1, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); + EXPECT_NE(ret, BError(BError::Codes::OK)); ret = proxy->AppFileReady(fileName, 0, 0); EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); bundleName = ""; fileName = ""; ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_NE(ret, BError(BError::Codes::OK)); + EXPECT_EQ(ret, BError(BError::Codes::OK)); EXPECT_EQ(fileName, ""); bundleName = "test"; ret = proxy->GetFileHandle(bundleName, fileName); diff --git a/tests/unittests/backup_sa/module_client/service_mock.cpp b/tests/unittests/backup_sa/module_client/service_mock.cpp deleted file mode 100644 index 2ff375bb1..000000000 --- a/tests/unittests/backup_sa/module_client/service_mock.cpp +++ /dev/null @@ -1,626 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "module_ipc/service.h" - -#include -#include -#include -#include - -#include "b_error/b_error.h" -#include "b_resources/b_constants.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; - -int32_t Service::GetUserIdDefault() -{ - return 0; -} - -void Service::OnStart() {} - -void Service::OnStop() {} - -ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd) -{ - fd = 1; - return BError(BError::Codes::OK); -} -ErrCode Service::InitBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - errMsg = "err"; - return BError(BError::Codes::OK); -} - -ErrCode Service::InitRestoreSessionWithErrMsg(const sptr &reverseIpcRemoteObject, std::string &errMsg) -{ - if (reverseIpcRemoteObject == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - errMsg = "err"; - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - int32_t restoreType, - int32_t userId) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (detailInfos.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (restoreType < 0 || userId < 0 || fd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSessionData(int fd, - const std::vector &bundleNames, - int32_t restoreType, - int32_t userId) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (restoreType < 0 || userId < 0 || fd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} -ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos( - const std::vector &bundlesToBackup, - const std::vector &bundleInfos) -{ - if (bundlesToBackup.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (bundleInfos.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::GetLocalCapabilities(int &fd) -{ - fd = 1; - return BError(BError::Codes::OK); -} - -UniqueFd Service::GetLocalCapabilities() -{ - return UniqueFd(-1); -} - -UniqueFd Service::GetLocalCapabilitiesForBundleInfos() -{ - return UniqueFd(-1); -} - -void Service::StopAll(const wptr &obj, bool force) {} - -ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::InitRestoreSession(const sptr &remote) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::InitBackupSession(const sptr &remote) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::Start() -{ - GTEST_LOG_(INFO) << "Service mock start"; - return BError(BError::Codes::OK); -} - -ErrCode Service::PublishFile(const BFileInfo &fileInfo) -{ - if (fileInfo.fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppFileReady(const string &fileName, int fd, int32_t errCode) -{ - if (fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (fd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppDone(ErrCode errCode) -{ - if (errCode == 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (errCode == -1) { - return BError(BError::BackupErrorCode::E_EMPTY); - } - if (errCode > 0) { - return BError(BError::Codes::OK); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo, BackupRestoreScenario sennario, ErrCode errCode) -{ - if (restoreRetInfo.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const std::vector &bundleNames, - RestoreTypeEnum restoreType, - int32_t userId) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesBackupSession(const std::vector &bundleNames) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector &bundleNames, - const std::vector &bundleInfos) -{ - if (bundleNames.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (bundleInfos.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::Finish() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -void Service::OnBackupExtensionDied(const string &&bundleName, bool isCleanCalled) {} - -void Service::ExtConnectDied(const string &callName) {} - -void Service::ExtStart(const string &bundleName) {} - -int Service::Dump(int fd, const vector &args) -{ - return 0; -} - -void Service::ExtConnectFailed(const string &bundleName, ErrCode ret) -{ - GTEST_LOG_(INFO) << "ExtConnectFailed is OK"; -} - -void Service::ExtConnectDone(string bundleName) {} - -void Service::ClearSessionAndSchedInfo(const string &bundleName) {} - -ErrCode Service::VerifyCaller() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario) -{ - return BError(BError::Codes::OK); -} - -void Service::OnAllBundlesFinished(ErrCode errCode) {} - -void Service::OnStartSched() {} - -void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {} - -void Service::SessionDeactive() {} - -ErrCode Service::Release() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::Cancel(const std::string &bundleName, int32_t &result) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (!bundleName.empty()) { - result = 0; - return BError(BError::Codes::OK); - } - result = BError(BError::Codes::OK); - return BError(BError::Codes::OK); -} - -ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector &bundleNames, int &fd) -{ - fd = 1; - return BError(BError::Codes::OK); -} - -ErrCode Service::GetAppLocalListAndDoIncrementalBackup() -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::InitIncrementalBackupSession(const sptr &remote) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr &remote, std::string &errMsg) -{ - if (remote == nullptr) { - return BError(BError::Codes::SA_BROKEN_IPC); - } - errMsg = "err"; - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector &bundlesToBackup, - const std::vector &infos) -{ - return BError(BError::Codes::OK); -} - -ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) -{ - if (fileInfo.fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd) -{ - if (fileInfo.fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::AppIncrementalFileReady(const std::string &fileName, - int fd, - int manifestFd, - int32_t appIncrementalFileReadyErrCode) -{ - if (fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (fd < 0 || manifestFd < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - - return BError(BError::Codes::OK); -} - -ErrCode Service::AppIncrementalDone(ErrCode errCode) -{ - if (errCode == 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (errCode == -1) { - return BError(BError::BackupErrorCode::E_EMPTY); - } - if (errCode > 0) { - return BError(BError::Codes::OK); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string &fileName) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - if (fileName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result) -{ - bundleName = "name"; - result = "abc"; - return BError(BError::Codes::OK); -} - -ErrCode Service::StartExtTimer(bool &isExtStart) -{ - if (isExtStart) { - return BError(BError::Codes::OK); - } - - return BError(BError::BackupErrorCode::E_TASKFAIL); -} - -ErrCode Service::StartFwkTimer(bool &isFwkStart) -{ - if (isFwkStart) { - return BError(BError::Codes::OK); - } - - return BError(BError::BackupErrorCode::E_TASKFAIL); -} - -ErrCode Service::StopExtTimer(bool &isExtStop) -{ - if (isExtStop) { - return BError(BError::Codes::OK); - } - return BError(BError::BackupErrorCode::E_TASKFAIL); -} - -ErrCode Service::RefreshDataSize(int64_t totalDatasize) -{ - if (totalDatasize < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - if (timeout < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - result = true; - return BError(BError::Codes::OK); -} - -ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result) -{ - if (bundleName.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - if (sendRate < 0) { - return BError(BError::BackupErrorCode::E_INVAL); - result = false; - } - result = true; - return BError(BError::Codes::OK); -} - -ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario) -{ - if (processInfo.empty()) { - return BError(BError::BackupErrorCode::E_INVAL); - } - return BError(BError::Codes::OK); -} - -void Service::OnSABackup(const std::string &bundleName, - const int &fd, - const std::string &result, - const ErrCode &errCode) -{ -} - -void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {} - -ErrCode Service::ClearResidualBundleData(const std::string &bundleName) -{ - return BError(BError::Codes::OK); -} - -std::shared_ptr Service::GetExtensionMutex(const BundleName &bundleName) -{ - return make_shared(bundleName); -} - -void Service::RemoveExtensionMutex(const BundleName &bundleName) {} - -void Service::OnBundleStarted(BError error, sptr session, const BundleName &bundleName) {} - -void Service::HandleExceptionOnAppendBundles(sptr session, - const vector &appendBundleNames, - const vector &restoreBundleNames) -{ -} - -void Service::BundleBeginRadarReport(const std::string &bundleName, - const ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::BundleEndRadarReport(const std::string &bundleName, - ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::FileReadyRadarReport(const std::string &bundleName, - const std::string &fileName, - const ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, - const ErrCode errCode, - const IServiceReverseType::Scenario scenario) -{ -} - -void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {} - -void Service::OnStartResRadarReport(const std::vector &bundleNameList, int32_t stage) {} - -std::string Service::GetCallerName() -{ - return ""; -} - -bool Service::IsReportBundleExecFail(const std::string &bundleName) -{ - return true; -} - -void Service::ClearBundleRadarReport() {} - -void Service::UpdateBundleRadarReport(const std::string &bundleName) {} - -bool Service::IsReportFileReadyFail(const std::string &bundleName) -{ - return true; -} - -void Service::ClearFileReadyRadarReport() {} - -void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {} - -void Service::ClearFailedBundles() {} - -void Service::GetOldDeviceBackupVersion() {} - -void Service::CreateDirIfNotExist(const std::string &path) {} - -void Service::StartRunningTimer(const std::string &bundleName) {} - -std::vector Service::GetSupportBackupBundleNames(vector &, - bool, - const vector &) -{ - return {}; -} - -void Service::HandleNotSupportBundleNames(const vector &, vector &, bool) {} - -void Service::SetBundleIncDataInfo(const std::vector &, std::vector &) {} - -void Service::CancelTask(std::string bundleName, wptr ptr) {} - -void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} - -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) -{ -} - -void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {} - -ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector &bundleNameList) -{ - return BError(BError::Codes::OK); -} - -void Service::GetDataSizeStepByStep(bool isPreciseScan, vector bundleNameList, string &scanning) {} - -void Service::GetPresumablySize(vector bundleNameList, string &scanning) {} - -void Service::GetPrecisesSize(vector bundleNameList, string &scanning) {} - -void Service::WriteToList(BJsonUtil::BundleDataSize bundleDataSize) {} - -void Service::DeleteFromList(size_t scannedSize) {} - -void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {} - -void Service::SendScannedInfo(const string &scannendInfos, sptr session) {} - -void Service::CyclicSendScannedInfo(bool isPreciseScan, vector bundleNameList) {} - -bool Service::GetScanningInfo(wptr obj, size_t scannedSize, string &scanning) -{ - return true; -} - -void Service::SetScanningInfo(string &scanning, string name) {} -} // namespace OHOS::FileManagement::Backup -- Gitee