1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <iostream> 17 #include <map> 18 #include <sstream> 19 20 #include "tools_op.h" 21 #include "tools_op_help.h" 22 #include <gtest/gtest.h> 23 24 namespace OHOS::FileManagement::Backup { 25 using namespace std; 26 class ToolsOpHelpTest : public testing::Test { 27 public: SetUpTestCase(void)28 static void SetUpTestCase(void) {}; TearDownTestCase()29 static void TearDownTestCase() {}; SetUp()30 void SetUp() {}; TearDown()31 void TearDown() {}; 32 }; 33 34 /** 35 * @tc.number: SUB_backup_tools_op_help_0101 36 * @tc.name: SUB_backup_tools_op_help_0101 37 * @tc.desc: 测试Execute分支 38 * @tc.size: MEDIUM 39 * @tc.type: FUNC 40 * @tc.level Level 1 41 * @tc.require: I6F3GV 42 */ 43 HWTEST_F(ToolsOpHelpTest, SUB_backup_tools_op_help_0101, testing::ext::TestSize.Level1) 44 { 45 GTEST_LOG_(INFO) << "ToolsOpHelpTest-begin SUB_backup_tools_op_help_0101"; 46 try { 47 GTEST_LOG_(INFO) << "ToolsOpHelpTest-info"; 48 HelpRegister(); 49 map<string, vector<string>> mapArgToVal; 50 vector<string> path = {"/data/backup/tmp"}; 51 mapArgToVal.insert(make_pair("pathCapFile", path)); 52 vector<string> bundles = {"com.example.app2backup"}; 53 mapArgToVal.insert(make_pair("bundles", bundles)); 54 vector<string> local = {"false"}; 55 mapArgToVal.insert(make_pair("isLocal", local)); 56 vector<string_view> curOp; 57 curOp.emplace_back("help"); __anone58e09f40102(const ToolsOp &op) 58 auto tryOpSucceed = [&curOp](const ToolsOp &op) { return op.TryMatch(curOp); }; 59 auto &&opeartions = ToolsOp::GetAllOperations(); 60 auto matchedOp = find_if(opeartions.begin(), opeartions.end(), tryOpSucceed); 61 if (matchedOp != opeartions.end()) { 62 matchedOp->Execute(mapArgToVal); 63 } 64 curOp.clear(); 65 curOp.emplace_back("backup"); 66 if (matchedOp != opeartions.end()) { 67 matchedOp->Execute(mapArgToVal); 68 } 69 } catch (...) { 70 EXPECT_TRUE(false); 71 GTEST_LOG_(INFO) << "ToolsOpHelpTest-an exception occurred by construction."; 72 } 73 GTEST_LOG_(INFO) << "ToolsOpHelpTest-end SUB_backup_tools_op_help_0101"; 74 } 75 } // namespace OHOS::FileManagement::Backup