• 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 <cstdlib>
17 #include <string>
18 
19 #include <sys/stat.h>
20 
21 #include <gtest/gtest.h>
22 
23 #include "b_process/b_process.h"
24 
25 namespace OHOS::FileManagement::Backup {
26 using namespace std;
27 
28 class BProcessTest : public testing::Test {
29 public:
SetUpTestCase()30     static void SetUpTestCase() {};
TearDownTestCase()31     static void TearDownTestCase() {};
SetUp()32     void SetUp() override {};
TearDown()33     void TearDown() override {};
34 };
35 
DetectFatalLog(string_view output)36 static bool DetectFatalLog(string_view output)
37 {
38     GTEST_LOG_(INFO) << "DetectFatalLog " << output;
39     if (output.find("empty archive") != string_view::npos) {
40         return true;
41     }
42     return false;
43 }
44 
45 /**
46  * @tc.number: SUB_backup_tool_BProcess_0100
47  * @tc.name: SUB_backup_tool_BProcess_0100
48  * @tc.desc: 测试ExecuteCmd
49  * @tc.size: MEDIUM
50  * @tc.type: FUNC
51  * @tc.level Level 0
52  * @tc.require: I6F3GV
53  */
54 HWTEST_F(BProcessTest, SUB_backup_tool_BProcess_0100, testing::ext::TestSize.Level0)
55 {
56     GTEST_LOG_(INFO) << "BProcessTest-begin SUB_backup_tool_BProcess_0100";
57     try {
58         vector<string_view> argvCf = {
59             "/system/bin/tar",
60             "-cf",
61             "/data/backup/",
62         };
63         auto [bFatalError, ret] = BProcess::ExecuteCmd(argvCf, DetectFatalLog);
64         EXPECT_NE(ret, 0);
65 
66         vector<string_view> argvTvf = {
67             "/system/bin/tar",
68             "-tvf",
69             "/data/backup/",
70         };
71         auto [bFatalErro1r, retTvf] = BProcess::ExecuteCmd(argvTvf, DetectFatalLog);
72         EXPECT_NE(retTvf, 0);
73     } catch (...) {
74         EXPECT_TRUE(false);
75         GTEST_LOG_(INFO) << "BProcessTest-an exception occurred.";
76     }
77     GTEST_LOG_(INFO) << "BProcessTest-end SUB_backup_tool_BProcess_0100";
78 }
79 } // namespace OHOS::FileManagement::Backup
80