• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 #include <iostream>
18 #include <map>
19 #include <sstream>
20 
21 #include "tools_op.h"
22 #include "utils_mock_global_variable.h"
23 
24 namespace OHOS::FileManagement::Backup {
25 using namespace std;
26 class ToolsOpCheckSaTest : 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_check_sa_0100
36  * @tc.name: SUB_backup_tools_op_check_sa_0100
37  * @tc.desc: 测试
38  * @tc.size: MEDIUM
39  * @tc.type: FUNC
40  * @tc.level Level 1
41  * @tc.require: I6F3GV
42  */
43 HWTEST_F(ToolsOpCheckSaTest, SUB_backup_tools_op_check_sa_0100, testing::ext::TestSize.Level1)
44 {
45     GTEST_LOG_(INFO) << "ToolsOpCheckSaTest-begin SUB_backup_tools_op_check_sa_0100";
46     try {
47         GTEST_LOG_(INFO) << "ToolsOpCheckSaTest-info";
48         map<string, vector<string>> mapArgToVal;
49         vector<string_view> curOp;
50         curOp.emplace_back("check");
51         curOp.emplace_back("sa");
__anonec1ec2230102(const ToolsOp &op) 52         auto tryOpSucceed = [&curOp](const ToolsOp &op) { return op.TryMatch(curOp); };
53         auto &&opeartions = ToolsOp::GetAllOperations();
54         auto matchedOp = find_if(opeartions.begin(), opeartions.end(), tryOpSucceed);
55         int ret = 0;
56         if (matchedOp != opeartions.end()) {
57             ret = matchedOp->Execute(mapArgToVal);
58             EXPECT_EQ(ret, 0);
59         }
60         GTEST_LOG_(INFO) << "GetInstance is false";
61         SetMockGetInstance(false);
62         if (matchedOp != opeartions.end()) {
63             ret = matchedOp->Execute(mapArgToVal);
64             EXPECT_NE(ret, 0);
65         }
66     } catch (...) {
67         EXPECT_TRUE(false);
68         GTEST_LOG_(INFO) << "ToolsOpCheckSaTest-an exception occurred by construction.";
69     }
70     GTEST_LOG_(INFO) << "ToolsOpCheckSaTest-end SUB_backup_tools_op_check_sa_0100";
71 }
72 } // namespace OHOS::FileManagement::Backup