• 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 <cstddef>
17 #include <string>
18 
19 #include <file_ex.h>
20 #include <gtest/gtest.h>
21 
22 #include "b_tarball/b_tarball_factory.h"
23 #include "test_manager.h"
24 
25 namespace OHOS::FileManagement::Backup {
26 using namespace std;
27 
28 class BTarballFactoryTest : public testing::Test {
29 public:
SetUpTestCase()30     static void SetUpTestCase() {};
TearDownTestCase()31     static void TearDownTestCase() {};
SetUp()32     void SetUp() {};
TearDown()33     void TearDown() {};
34 };
35 
36 /**
37  * @tc.number: SUB_b_tarball_factory_0100
38  * @tc.name: b_tarball_factory_0100
39  * @tc.desc: 测试BTarballFactory类create函数是否成功
40  * @tc.size: MEDIUM
41  * @tc.type: FUNC
42  * @tc.level Level 1
43  * @tc.require: I6F3GV
44  */
45 HWTEST_F(BTarballFactoryTest, b_tarball_factory_0100, testing::ext::TestSize.Level1)
46 {
47     GTEST_LOG_(INFO) << "BTarballFactoryTest-begin b_tarball_factory_0100";
48     try {
49         // 预置路径
50         TestManager tm("b_tarball_factory_0100");
51         string root = tm.GetRootDirCurTest();
52         string implType = "cmdline";
53         string tarballPath = root + "/test.tar";
54         SaveStringToFile(tarballPath, "data/storage/el2/database/");
55         // 调用create获取打包解包能力
56         auto tarballTar = BTarballFactory::Create(implType, tarballPath);
57         GTEST_LOG_(INFO) << "BTarballFactoryTest-tar";
58         (tarballTar->tar)("/", {}, {"/data/storage/el2/database/", {}});
59         GTEST_LOG_(INFO) << "BTarballFactoryTest-untar";
60         (tarballTar->untar)("/");
61     } catch (...) {
62         EXPECT_TRUE(false);
63         GTEST_LOG_(INFO) << "BTarballFactoryTest-an exception occurred by BTarballFactory.";
64     }
65     GTEST_LOG_(INFO) << "BTarballFactoryTest-end b_tarball_factory_0100";
66 }
67 } // namespace OHOS::FileManagement::Backup