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 <gtest/gtest.h> 21 22 #include "tools_op.h" 23 24 namespace OHOS::FileManagement::Backup { 25 using namespace std; 26 class ToolsOpTest : 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_0100 36 * @tc.name: SUB_backup_tools_op_0100 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(ToolsOpTest, SUB_backup_tools_op_0100, testing::ext::TestSize.Level1) 44 { 45 GTEST_LOG_(INFO) << "ToolsOpTest-begin SUB_backup_tools_op_0100"; 46 try { 47 GTEST_LOG_(INFO) << "ToolsOpTest-info"; 48 bool autoTest = ToolsOp::Register(ToolsOp {ToolsOp::Descriptor { 49 .opName = {"test"}, 50 .funcGenHelpMsg = nullptr, 51 .funcExec = nullptr, 52 }}); 53 EXPECT_TRUE(autoTest); 54 map<string, vector<string>> mapArgToVal; 55 vector<string_view> curOp; 56 curOp.emplace_back("test"); __anon0f3f5ab30102(const ToolsOp &op) 57 auto tryOpSucceed = [&curOp](const ToolsOp &op) { return op.TryMatch(curOp); }; 58 auto &&opeartions = ToolsOp::GetAllOperations(); 59 auto matchedOp = find_if(opeartions.begin(), opeartions.end(), tryOpSucceed); 60 if (matchedOp != opeartions.end()) { 61 matchedOp->Execute(mapArgToVal); 62 } 63 } catch (...) { 64 EXPECT_TRUE(false); 65 GTEST_LOG_(INFO) << "ToolsOpTest-an exception occurred by construction."; 66 } 67 GTEST_LOG_(INFO) << "ToolsOpTest-end SUB_backup_tools_op_0100"; 68 } 69 70 /** 71 * @tc.number: SUB_backup_tools_op_0200 72 * @tc.name: SUB_backup_tools_op_0200 73 * @tc.desc: 测试Register分支 74 * @tc.size: MEDIUM 75 * @tc.type: FUNC 76 * @tc.level Level 1 77 * @tc.require: I6F3GV 78 */ 79 HWTEST_F(ToolsOpTest, SUB_backup_tools_op_0200, testing::ext::TestSize.Level1) 80 { 81 GTEST_LOG_(INFO) << "ToolsOpTest-begin SUB_backup_tools_op_0200"; 82 try { 83 GTEST_LOG_(INFO) << "ToolsOpTest-info"; 84 bool autoTest = ToolsOp::Register(ToolsOp {ToolsOp::Descriptor { 85 .opName = {"???"}, 86 .funcGenHelpMsg = nullptr, 87 .funcExec = nullptr, 88 }}); 89 EXPECT_FALSE(autoTest); 90 } catch (...) { 91 EXPECT_TRUE(false); 92 GTEST_LOG_(INFO) << "ToolsOpTest-an exception occurred by construction."; 93 } 94 GTEST_LOG_(INFO) << "ToolsOpTest-end SUB_backup_tools_op_0200"; 95 } 96 } // namespace OHOS::FileManagement::Backup