From ec91854ce2a2ca1626ed04e3dcf41b1b75f348ed Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Fri, 21 Jul 2023 14:26:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8DTDD?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- .../b_session_restore_async_mock.cpp | 106 ++++++++ tests/moduletests/backup_kit_inner/BUILD.gn | 2 + .../b_session_restore_async_test.cpp | 226 ++++++++++++++++++ tests/moduletests/backup_tool/BUILD.gn | 5 +- .../backup_tool/tool_backup_restore_test.cpp | 31 --- tests/unittests/backup_tools/BUILD.gn | 3 + .../tools_op_restore_async_test.cpp | 172 +++++++++++++ 7 files changed, 510 insertions(+), 35 deletions(-) create mode 100644 tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp create mode 100644 tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp delete mode 100644 tests/moduletests/backup_tool/tool_backup_restore_test.cpp create mode 100644 tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp diff --git a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp new file mode 100644 index 000000000..76ddbb901 --- /dev/null +++ b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2023 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 "b_session_restore_async.h" + +#include +#include +#include +#include + +#include +#include + +#include "b_error/b_error.h" +#include "test_manager.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +namespace { +static BSessionRestoreAsync::Callbacks callbacks_ = {}; +static vector bundlesToRestore_ = {}; +} // namespace + +BSessionRestoreAsync::~BSessionRestoreAsync() {} + +shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsync::Init"; + try { + auto restore = make_shared(callbacks); + return restore; + } catch (const exception &e) { + return nullptr; + } + return nullptr; +} + +ErrCode BSessionRestoreAsync::PublishFile(BFileInfo fileInfo) +{ + return BError(BError::Codes::OK); +} + +ErrCode BSessionRestoreAsync::GetFileHandle(const string &bundleName, const string &fileName) +{ + return BError(BError::Codes::OK); +} + +ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + RestoreTypeEnum restoreType, + int32_t userId) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsync::AppendBundles"; + if (restoreType == RestoreTypeEnum::RESTORE_DATA_READDY) { + callbacks_.onBackupServiceDied(); + return BError(BError::Codes::OK); + } + callbacks_.onBundleStarted(0, "com.example.app2backup"); + + BFileInfo bFileInfo("com.example.app2backup", "1.tar", 0); + TestManager tm("BSessionRestoreAsyncMock_GetFd_0100"); + string filePath = tm.GetRootDirCurTest().append("1.tar"); + UniqueFd fd(open(filePath.data(), O_RDWR | O_CREAT, S_IRWXU)); + GTEST_LOG_(INFO) << "callbacks_::onFileReady 1.tar"; + callbacks_.onFileReady(bFileInfo, move(fd)); + + string fileManagePath = tm.GetRootDirCurTest().append("manage.json"); + UniqueFd fdManage(open(fileManagePath.data(), O_RDWR | O_CREAT, S_IRWXU)); + bFileInfo.fileName = "manage.json"; + GTEST_LOG_(INFO) << "callbacks_::onFileReady manage.json"; + callbacks_.onFileReady(bFileInfo, move(fdManage)); + + callbacks_.onBundleFinished(0, "com.example.app2backup"); + + callbacks_.onAllBundlesFinished(0); + callbacks_.onBundleStarted(1, "com.example.app2backup"); + callbacks_.onBundleFinished(1, "com.example.app2backup"); + callbacks_.onAllBundlesFinished(1); + + callbacks_.onBackupServiceDied(); + return BError(BError::Codes::OK); +} + +void BSessionRestoreAsync::OnBackupServiceDied() {} + +void BSessionRestoreAsync::PopBundleInfo() {} + +void BSessionRestoreAsync::AppendBundlesImpl(AppendBundleInfo info) {} + +void BSessionRestoreAsync::OnBundleStarted(ErrCode errCode, const vector &bundlesToRestore) {} + +void BSessionRestoreAsync::RegisterBackupServiceDied(function functor) {} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/moduletests/backup_kit_inner/BUILD.gn b/tests/moduletests/backup_kit_inner/BUILD.gn index 3f36ffc08..d506df4c4 100644 --- a/tests/moduletests/backup_kit_inner/BUILD.gn +++ b/tests/moduletests/backup_kit_inner/BUILD.gn @@ -20,9 +20,11 @@ ohos_unittest("b_session_test") { sources = [ "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_backup.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore.cpp", + "${path_backup}/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse.cpp", "${path_backup}/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp", "b_session_backup_test.cpp", + "b_session_restore_async_test.cpp", "b_session_restore_test.cpp", ] sources += backup_mock_proxy_src diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp new file mode 100644 index 000000000..f53da7733 --- /dev/null +++ b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2023 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 +#include +#include + +#include "b_error/b_error.h" +#include "b_file_info.h" +#include "backup_kit_inner.h" +#include "unique_fd.h" +#include "utils_mock_global_variable.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +static void OnFileReady(const BFileInfo &fileInfo, UniqueFd fd) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnFileReady OK"; +} + +static void OnBundleStarted(ErrCode err, const BundleName name) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnBundleStarted OK"; +} + +static void OnBundleFinished(ErrCode err, const BundleName name) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnBundleFinished OK"; +} + +static void OnAllBundlesFinished(ErrCode err) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnAllBundlesFinished OK"; +} + +static void OnBackupServiceDied() +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnBackupServiceDied OK"; +} + +class BSessionRestoreAsyncTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() override; + void TearDown() override; + + void Init(); + + shared_ptr restorePtr_; + BSessionRestoreAsync::Callbacks callbacks_; +}; + +void BSessionRestoreAsyncTest::SetUp() +{ + SetMockInitBackupOrRestoreSession(true); + SetMockGetInstance(true); + SetMockLoadSystemAbility(true); + restorePtr_ = make_shared(callbacks_); +} + +void BSessionRestoreAsyncTest::TearDown() +{ + restorePtr_ = nullptr; +} + +void BSessionRestoreAsyncTest::Init() +{ + callbacks_.onFileReady = OnFileReady; + callbacks_.onBundleStarted = OnBundleStarted; + callbacks_.onBundleFinished = OnBundleFinished; + callbacks_.onAllBundlesFinished = OnAllBundlesFinished; + callbacks_.onBackupServiceDied = OnBackupServiceDied; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0100 + * @tc.name: SUB_backup_b_session_restore_async_0100 + * @tc.desc: 测试Callbacks接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0100"; + try { + Init(); + BFileInfo bFileInfo("", "", 0); + callbacks_.onFileReady(bFileInfo, UniqueFd(-1)); + callbacks_.onBundleStarted(ErrCode(BError::Codes::OK), ""); + callbacks_.onBundleFinished(ErrCode(BError::Codes::OK), ""); + callbacks_.onAllBundlesFinished(ErrCode(BError::Codes::OK)); + callbacks_.onBackupServiceDied(); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by Callbacks."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0100"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0200 + * @tc.name: SUB_backup_b_session_restore_async_0200 + * @tc.desc: 测试Init接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0200"; + try { + auto restorePtr = BSessionRestoreAsync::Init(callbacks_); + EXPECT_NE(restorePtr, nullptr); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by Init."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0200"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0300 + * @tc.name: SUB_backup_b_session_restore_async_0300 + * @tc.desc: 测试PublishFile接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0300, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0300"; + try { + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + BFileInfo bFileInfo("", "", 0); + auto ret = restorePtr_->PublishFile(bFileInfo); + EXPECT_NE(ret, ErrCode(BError::Codes::OK)); + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + ret = restorePtr_->PublishFile(bFileInfo); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by PublishFile."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0300"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0400 + * @tc.name: SUB_backup_b_session_restore_async_0400 + * @tc.desc: 测试GetFileHandle接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0400, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0400"; + try { + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + string bundleName = ""; + string fileName = ""; + auto ret = restorePtr_->GetFileHandle(bundleName, fileName); + EXPECT_NE(ret, ErrCode(BError::Codes::OK)); + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + ret = restorePtr_->GetFileHandle(bundleName, fileName); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by GetFileHandle."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0400"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0500 + * @tc.name: SUB_backup_b_session_restore_async_0500 + * @tc.desc: 测试AppendBundles接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0500"; + try { + SetMockGetInstance(true); + SetMockLoadSystemAbility(true); + vector bundleNames; + ErrCode ret = restorePtr_->AppendBundles(UniqueFd(-1), bundleNames); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + ret = restorePtr_->AppendBundles(UniqueFd(-1), bundleNames); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + restorePtr_ = nullptr; + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by ~BSessionRestoreAsync."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0500"; +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/moduletests/backup_tool/BUILD.gn b/tests/moduletests/backup_tool/BUILD.gn index 6e39dd850..177c8e10b 100644 --- a/tests/moduletests/backup_tool/BUILD.gn +++ b/tests/moduletests/backup_tool/BUILD.gn @@ -17,10 +17,7 @@ import("//foundation/filemanagement/app_file_service/backup.gni") ohos_unittest("tools_op_test") { module_out_path = path_module_out_tests - sources = [ - "tool_backup_restore_test.cpp", - "tool_help_test.cpp", - ] + sources = [ "tool_help_test.cpp" ] deps = [ "${path_backup}/tests/utils:backup_test_utils", diff --git a/tests/moduletests/backup_tool/tool_backup_restore_test.cpp b/tests/moduletests/backup_tool/tool_backup_restore_test.cpp deleted file mode 100644 index e0ab9397a..000000000 --- a/tests/moduletests/backup_tool/tool_backup_restore_test.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022-2023 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 "b_process/b_process.h" -#include "test_manager.h" -#include "gtest/gtest.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -class ToolsTest : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_tools/BUILD.gn b/tests/unittests/backup_tools/BUILD.gn index b4ec6c1fc..636eef003 100644 --- a/tests/unittests/backup_tools/BUILD.gn +++ b/tests/unittests/backup_tools/BUILD.gn @@ -59,9 +59,12 @@ ohos_unittest("backup_tool_restore_test") { sources = [ "${path_backup_mock}/b_filesystem/b_file_mock.cpp", + "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp", "${path_backup}/tests/mock/backup_kit_inner/b_session_restore_mock.cpp", "${path_backup}/tools/backup_tool/src/tools_op.cpp", "${path_backup}/tools/backup_tool/src/tools_op_restore.cpp", + "${path_backup}/tools/backup_tool/src/tools_op_restore_async.cpp", + "backup_tool/tools_op_restore_async_test.cpp", "backup_tool/tools_op_restore_test.cpp", ] sources += backup_mock_proxy_src diff --git a/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp new file mode 100644 index 000000000..0ace5d071 --- /dev/null +++ b/tests/unittests/backup_tools/backup_tool/tools_op_restore_async_test.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2023 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 + +#include + +#include "b_resources/b_constants.h" +#include "tools_op.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +namespace { +const string BUNDLE_NAME = "com.example.app2backup/"; +const string MANAGE_JSON = "manage.json"; +const string FILE_NAME = "1.tar"; +} // namespace + +class ToolsOpRestoreAsyncTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number: SUB_backup_tools_op_restore_async_0100 + * @tc.name: SUB_backup_tools_op_restore_async_0100 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(ToolsOpRestoreAsyncTest, SUB_backup_tools_op_restore_async_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin SUB_backup_tools_op_restore_async_0100"; + try { + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-info"; + map> mapArgToVal; + string localCap = string(BConstants::SA_BUNDLE_BACKUP_TMP_DIR.data()) + "/tmp"; + vector path = {localCap.data()}; + mapArgToVal.insert(make_pair("pathCapFile", path)); + vector bundles = {"com.example.app2backup"}; + mapArgToVal.insert(make_pair("bundles", bundles)); + vector restoreType = {"true"}; + mapArgToVal.insert(make_pair("restoreType", restoreType)); + vector userId = {"100"}; + mapArgToVal.insert(make_pair("userId", userId)); + + // 创建测试路径以及测试环境 + string cmdMkdir = string("mkdir -p ") + BConstants::BACKUP_TOOL_RECEIVE_DIR.data() + BUNDLE_NAME; + system(cmdMkdir.c_str()); + string cmdTool = string("mkdir -p ") + BConstants::SA_BUNDLE_BACKUP_TMP_DIR.data(); + system(cmdTool.c_str()); + string touchTar = string("touch ") + BConstants::BACKUP_TOOL_RECEIVE_DIR.data() + BUNDLE_NAME + FILE_NAME; + system(touchTar.c_str()); + string touchManage = string("touch ") + BConstants::BACKUP_TOOL_RECEIVE_DIR.data() + BUNDLE_NAME + MANAGE_JSON; + system(touchManage.c_str()); + string touchTmp = string("touch ") + localCap; + system(touchTmp.c_str()); + + // 尝试匹配当前命令,成功后执行 + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-restoreAsync"; + vector curOp; + curOp.emplace_back("restoreAsync"); + auto tryOpSucceed = [&curOp](const ToolsOp &op) { return op.TryMatch(curOp); }; + auto &&opeartions = ToolsOp::GetAllOperations(); + auto matchedOp = find_if(opeartions.begin(), opeartions.end(), tryOpSucceed); + if (matchedOp != opeartions.end()) { + auto ret = matchedOp->Execute(mapArgToVal); + EXPECT_EQ(ret, 0); + } + + mapArgToVal.clear(); + mapArgToVal.insert(make_pair("pathCapFile", path)); + mapArgToVal.insert(make_pair("bundles", bundles)); + vector restoreTypeF = {"false"}; + mapArgToVal.insert(make_pair("restoreType", restoreTypeF)); + mapArgToVal.insert(make_pair("userId", userId)); + if (matchedOp != opeartions.end()) { + auto ret = matchedOp->Execute(mapArgToVal); + EXPECT_EQ(ret, 0); + } + + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end SUB_backup_tools_op_restore_async_0100"; +} + +/** + * @tc.number: SUB_backup_tools_op_restore_async_0200 + * @tc.name: SUB_backup_tools_op_restore_async_0200 + * @tc.desc: 测试 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(ToolsOpRestoreAsyncTest, SUB_backup_tools_op_restore_async_0200, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-begin SUB_backup_tools_op_restore_async_0200"; + try { + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-The pathCapFile field is not contained."; + map> mapArgToVal; + vector bundles = {"com.example.app2backup"}; + vector path = {"/data/backup/tmp"}; + mapArgToVal.insert(make_pair("bundles", bundles)); + vector restoreType = {"false"}; + mapArgToVal.insert(make_pair("restoreType", restoreType)); + vector userId = {"100"}; + mapArgToVal.insert(make_pair("userId", userId)); + + vector curOp; + curOp.emplace_back("restoreAsync"); + auto tryOpSucceed = [&curOp](const ToolsOp &op) { return op.TryMatch(curOp); }; + auto &&opeartions = ToolsOp::GetAllOperations(); + auto matchedOp = find_if(opeartions.begin(), opeartions.end(), tryOpSucceed); + if (matchedOp == opeartions.end()) { + EXPECT_TRUE(false); + return; + } + int ret = 0; + ret = matchedOp->Execute(mapArgToVal); + EXPECT_NE(ret, 0); + + mapArgToVal.clear(); + mapArgToVal.insert(make_pair("pathCapFile", path)); + ret = matchedOp->Execute(mapArgToVal); + EXPECT_NE(ret, 0); + + mapArgToVal.clear(); + mapArgToVal.insert(make_pair("pathCapFile", path)); + mapArgToVal.insert(make_pair("bundles", bundles)); + ret = matchedOp->Execute(mapArgToVal); + EXPECT_NE(ret, 0); + + mapArgToVal.clear(); + mapArgToVal.insert(make_pair("pathCapFile", path)); + mapArgToVal.insert(make_pair("bundles", bundles)); + mapArgToVal.insert(make_pair("restoreType", restoreType)); + ret = matchedOp->Execute(mapArgToVal); + EXPECT_NE(ret, 0); + + mapArgToVal.clear(); + ret = matchedOp->Execute(mapArgToVal); + EXPECT_NE(ret, 0); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-an exception occurred by construction."; + } + GTEST_LOG_(INFO) << "ToolsOpRestoreAsyncTest-end SUB_backup_tools_op_restore_async_0200"; +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee