• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 AppExecFwk {
23 namespace LIBZIP {
24 using namespace testing::ext;
25 
26 namespace {
27 const std::string BASE_PATH = "/data/app/el2/100/base/";
28 const std::string APP_PATH = "com.example.zlib/com.example.zlib/com.example.zlib.MainAbility/files/";
29 }  // namespac
30 class ZipTest : public testing::Test {
31 public:
ZipTest()32     ZipTest()
33     {}
~ZipTest()34     ~ZipTest()
35     {}
36 
37     static void SetUpTestCase(void);
38     static void TearDownTestCase(void);
39     void SetUp();
40     void TearDown();
41 };
42 
SetUpTestCase(void)43 void ZipTest::SetUpTestCase(void)
44 {}
45 
TearDownTestCase(void)46 void ZipTest::TearDownTestCase(void)
47 {}
48 
SetUp()49 void ZipTest::SetUp()
50 {}
51 
TearDown()52 void ZipTest::TearDown()
53 {}
54 
ZipCallBack(int result)55 void ZipCallBack(int result)
56 {
57     printf("--Zip--callback--result=%d--\n", result);
58 }
UnzipCallBack(int result)59 void UnzipCallBack(int result)
60 {
61     printf("--UnZip--callback--result=%d--\n", result);
62 }
63 
64 /**
65  * @tc.number: APPEXECFWK_LIBZIP_zip_0100_8file
66  * @tc.name: zip_0100_8file
67  * @tc.desc:
68  */
69 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_zip_0100_8file, Function | MediumTest | Level1)
70 {
71     std::string src = BASE_PATH + APP_PATH + "test";
72     std::string dest = BASE_PATH + APP_PATH + "result/8file.zip";
73 
74     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
75     auto ret = Zip(src, dest, false, zlibCallbackInfo);
76     EXPECT_TRUE(ret);
77     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
78 }
79 
80 /**
81  * @tc.number: APPEXECFWK_LIBZIP_zip_0200_1file
82  * @tc.name: zip_0200_1file
83  * @tc.desc:
84  */
85 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_zip_0200_1file, Function | MediumTest | Level1)
86 {
87     std::string src = BASE_PATH + APP_PATH + "test/01";
88     std::string dest = BASE_PATH + APP_PATH + "result/1file.zip";
89 
90     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
91     auto ret = Zip(src, dest, false, zlibCallbackInfo);
92     EXPECT_TRUE(ret);
93     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
94 }
95 
96 /**
97  * @tc.number: APPEXECFWK_LIBZIP_zip_0100_zip1file
98  * @tc.name: zip_0100_zip1file
99  * @tc.desc:
100  */
101 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_zip_0100_zip1file, Function | MediumTest | Level1)
102 {
103     std::string src = BASE_PATH + APP_PATH + "test/01/zip1.txt";
104     std::string dest = BASE_PATH + APP_PATH + "result/zip1file.zip";
105 
106     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
107     auto ret = Zip(src, dest, false, zlibCallbackInfo);
108     EXPECT_TRUE(ret);
109     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
110 }
111 
112 /**
113  * @tc.number: APPEXECFWK_LIBZIP_unzip_0100_8file
114  * @tc.name: unzip_0100_8file
115  * @tc.desc:
116  */
117 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_unzip_0100_8file, Function | MediumTest | Level1)
118 {
119     std::string src = BASE_PATH + APP_PATH + "result/8file.zip";
120     std::string dest = BASE_PATH + APP_PATH + "unzip/01";
121 
122     OPTIONS options;
123     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
124     auto ret = Unzip(src, dest, options, zlibCallbackInfo);
125     EXPECT_FALSE(ret);
126     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
127 }
128 /**
129  * @tc.number: APPEXECFWK_LIBZIP_unzip_single_0200_1file
130  * @tc.name: unzip_single_0200_1file
131  * @tc.desc:
132  */
133 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_unzip_single_0200_1file, Function | MediumTest | Level1)
134 {
135     std::string src = BASE_PATH + APP_PATH + "result/1file.zip";
136     std::string dest = BASE_PATH + APP_PATH + "unzip/02";
137 
138     OPTIONS options;
139     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
140     auto ret = Unzip(src, dest, options, zlibCallbackInfo);
141     EXPECT_FALSE(ret);
142     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
143 }
144 /**
145  * @tc.number: APPEXECFWK_LIBZIP_zip_0100_zip1file
146  * @tc.name: zip_0100_zip1file
147  * @tc.desc:
148  */
149 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_unzip_0100_zip1file, Function | MediumTest | Level1)
150 {
151     std::string src = BASE_PATH + APP_PATH + "result/zip1file.zip";
152     std::string dest = BASE_PATH + APP_PATH + "unzip/zip1file";
153 
154     OPTIONS options;
155     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
156     auto ret = Unzip(src, dest, options, zlibCallbackInfo);
157     EXPECT_FALSE(ret);
158     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
159 }
160 
161 /**
162  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0100
163  * @tc.name: Checkzip_0100
164  * @tc.desc:
165  */
166 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0100, Function | MediumTest | Level1)
167 {
168     std::string src = BASE_PATH + APP_PATH + "test";
169     std::string dest = BASE_PATH + APP_PATH + "check";
170     FilePath destFile(dest);
171 
172     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
173     auto ret = Zip(src, dest, false, zlibCallbackInfo);
174     destFile.CheckDestDirTail();
175     FilePath newDestFile(destFile.CheckDestDirTail());
176     std::cout << newDestFile.Value() << std::endl;
177     EXPECT_TRUE(ret);
178     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
179 }
180 
181 /**
182  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0200
183  * @tc.name: Checkzip_0200
184  * @tc.desc:
185  */
186 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0200, Function | MediumTest | Level1)
187 {
188     std::string src = BASE_PATH + APP_PATH + "test";
189     std::string dest = BASE_PATH + APP_PATH + "error/check.zip";
190 
191     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
192     auto ret = Zip(src, dest, false, zlibCallbackInfo);
193     EXPECT_TRUE(ret);
194     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
195 }
196 
197 /**
198  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0300
199  * @tc.name: Checkzip_0300
200  * @tc.desc:
201  */
202 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0300, Function | MediumTest | Level1)
203 {
204     std::string src = BASE_PATH + APP_PATH + "error";
205     std::string src1 = BASE_PATH + APP_PATH + "#%#@$%";
206     std::string src2 = BASE_PATH + APP_PATH + "error/error1";
207     std::string dest = BASE_PATH + APP_PATH + "/check.zip";
208 
209     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
210     auto ret1 = Zip(src, dest, false, zlibCallbackInfo);
211     auto ret2 = Zip(src1, dest, false, zlibCallbackInfo);
212     auto ret3 = Zip(src2, dest, false, zlibCallbackInfo);
213     EXPECT_TRUE(ret1);
214     EXPECT_TRUE(ret2);
215     EXPECT_TRUE(ret3);
216     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
217 }
218 
219 /**
220  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0400
221  * @tc.name: Checkzip_0400
222  * @tc.desc:
223  */
224 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0400, Function | MediumTest | Level1)
225 {
226     std::string src1 = BASE_PATH + APP_PATH + "error.txt";
227     std::string dest = BASE_PATH + APP_PATH + "check.zip";
228     FilePath srcFile1(src1);
229 
230     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
231     auto ret = Zip(src1, dest, false, zlibCallbackInfo);
232     EXPECT_TRUE(ret);
233     std::cout << "srcFile1  DirName: " << srcFile1.DirName().Value() << std::endl;
234     std::cout << "srcFile1  Value:   " << srcFile1.Value() << std::endl;
235     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
236 }
237 
238 /**
239  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0500
240  * @tc.name: Checkzip_0500
241  * @tc.desc:
242  */
243 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0500, Function | MediumTest | Level1)
244 {
245     std::string src = BASE_PATH + APP_PATH + "error";
246     std::string dest = BASE_PATH + APP_PATH + "error1";
247 
248     OPTIONS options;
249     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
250     auto ret = Unzip(src, dest, options, zlibCallbackInfo);
251     EXPECT_FALSE(ret);
252     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
253 }
254 
255 /**
256  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0600
257  * @tc.name: Checkzip_0600
258  * @tc.desc:
259  */
260 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0600, Function | MediumTest | Level1)
261 {
262     std::string src = BASE_PATH + APP_PATH + "test";
263     std::string dest = "";
264 
265     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
266     auto ret = Zip(src, dest, false, zlibCallbackInfo);
267     EXPECT_FALSE(ret);
268     std::cout << dest << std::endl;
269     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
270 }
271 
272 /**
273  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0700
274  * @tc.name: Checkzip_0700
275  * @tc.desc:
276  */
277 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0700, Function | MediumTest | Level1)
278 {
279     std::string src = "";
280     std::string dest = BASE_PATH + APP_PATH;
281     FilePath destFile(dest);
282 
283     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
284     auto ret = Zip(src, dest, false, zlibCallbackInfo);
285     EXPECT_FALSE(ret);
286     destFile.CheckDestDirTail();
287     FilePath newDestFile(destFile.CheckDestDirTail());
288     std::cout << newDestFile.Value() << std::endl;
289     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
290 }
291 
292 /**
293  * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0800
294  * @tc.name: Checkzip_0800
295  * @tc.desc:
296  */
297 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0800, Function | MediumTest | Level1)
298 {
299     std::string src = "";
300     std::string dest = BASE_PATH + APP_PATH;
301 
302     OPTIONS options;
303     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
304     auto ret = Unzip(src, dest, options, zlibCallbackInfo);
305     EXPECT_FALSE(ret);
306     std::this_thread::sleep_for(std::chrono::milliseconds(5000));
307 }
308 }  // namespace LIBZIP
309 }  // namespace AppExecFwk
310 }  // namespace OHOS
311