• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include <gtest/gtest.h>
16 #include <memory>
17 #include <thread>
18 
19 #include "zip.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
23 namespace LIBZIP {
24 using namespace testing::ext;
25 
26 class ZipTest : public testing::Test {
27 public:
ZipTest()28     ZipTest()
29     {}
~ZipTest()30     ~ZipTest()
31     {}
32 
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase(void)39 void ZipTest::SetUpTestCase(void)
40 {}
41 
TearDownTestCase(void)42 void ZipTest::TearDownTestCase(void)
43 {}
44 
SetUp()45 void ZipTest::SetUp()
46 {}
47 
TearDown()48 void ZipTest::TearDown()
49 {}
50 
ZipCallBack(int result)51 void ZipCallBack(int result)
52 {
53     printf("--Zip--callback--result=%d--\n", result);
54 }
UnzipCallBack(int result)55 void UnzipCallBack(int result)
56 {
57     printf("--UnZip--callback--result=%d--\n", result);
58 }
59 
60 /**
61  * @tc.number:
62  * @tc.name:
63  * @tc.desc:
64  */
65 HWTEST_F(ZipTest, AAFwk_LIBZIP_zip_0100_fourfile, Function | MediumTest | Level1)
66 {
67     std::string src = "/ziptest/zipdata/";
68     std::string dest = "/ziptest/result/fourfile.zip";
69 
70     OPTIONS options;
71     Zip(FilePath(src), FilePath(dest), options, ZipCallBack, false);
72     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
73 }
74 
75 /**
76  * @tc.number:
77  * @tc.name:
78  * @tc.desc:
79  */
80 HWTEST_F(ZipTest, AAFwk_LIBZIP_zip_0200_singlefile, Function | MediumTest | Level1)
81 {
82     std::string src = "/ziptest/zipdata/zip1/zip1-1/zip1-1.cpp";
83     std::string dest = "/ziptest/result/singlefile.zip";
84 
85     OPTIONS options;
86     Zip(FilePath(src), FilePath(dest), options, ZipCallBack, false);
87     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
88 }
89 
90 /**
91  * @tc.number:
92  * @tc.name:
93  * @tc.desc:
94  */
95 HWTEST_F(ZipTest, AAFwk_LIBZIP_unzip_0100, Function | MediumTest | Level1)
96 {
97     std::string dest = "/ziptest/unzipdir/fourfile/";
98     std::string src = "/ziptest/result/fourfile.zip";
99 
100     OPTIONS options;
101     Unzip(FilePath(src), FilePath(dest), options, UnzipCallBack);
102     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
103 }
104 
105 HWTEST_F(ZipTest, AAFwk_LIBZIP_unzip_single_0200, Function | MediumTest | Level1)
106 {
107     std::string src = "/ziptest/result/singlefile.zip";
108     std::string dest = "/ziptest/unzipdir/single/";
109 
110     OPTIONS options;
111     Unzip(FilePath(src), FilePath(dest), options, UnzipCallBack);
112     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
113 }
114 
115 }  // namespace LIBZIP
116 }  // namespace AAFwk
117 }  // namespace OHOS