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 Zip(src, dest, false, zlibCallbackInfo);
76 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
77 }
78
79 /**
80 * @tc.number: APPEXECFWK_LIBZIP_zip_0200_1file
81 * @tc.name: zip_0200_1file
82 * @tc.desc:
83 */
84 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_zip_0200_1file, Function | MediumTest | Level1)
85 {
86 std::string src = BASE_PATH + APP_PATH + "test/01";
87 std::string dest = BASE_PATH + APP_PATH + "result/1file.zip";
88
89 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
90 Zip(src, dest, false, zlibCallbackInfo);
91 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
92 }
93
94 /**
95 * @tc.number: APPEXECFWK_LIBZIP_zip_0100_zip1file
96 * @tc.name: zip_0100_zip1file
97 * @tc.desc:
98 */
99 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_zip_0100_zip1file, Function | MediumTest | Level1)
100 {
101 std::string src = BASE_PATH + APP_PATH + "test/01/zip1.txt";
102 std::string dest = BASE_PATH + APP_PATH + "result/zip1file.zip";
103
104 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
105 Zip(src, dest, false, zlibCallbackInfo);
106 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
107 }
108
109 /**
110 * @tc.number: APPEXECFWK_LIBZIP_unzip_0100_8file
111 * @tc.name: unzip_0100_8file
112 * @tc.desc:
113 */
114 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_unzip_0100_8file, Function | MediumTest | Level1)
115 {
116 std::string src = BASE_PATH + APP_PATH + "result/8file.zip";
117 std::string dest = BASE_PATH + APP_PATH + "unzip/01";
118
119 OPTIONS options;
120 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
121 Unzip(src, dest, options, zlibCallbackInfo);
122 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
123 }
124 /**
125 * @tc.number: APPEXECFWK_LIBZIP_unzip_single_0200_1file
126 * @tc.name: unzip_single_0200_1file
127 * @tc.desc:
128 */
129 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_unzip_single_0200_1file, Function | MediumTest | Level1)
130 {
131 std::string src = BASE_PATH + APP_PATH + "result/1file.zip";
132 std::string dest = BASE_PATH + APP_PATH + "unzip/02";
133
134 OPTIONS options;
135 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
136 Unzip(src, dest, options, zlibCallbackInfo);
137 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
138 }
139 /**
140 * @tc.number: APPEXECFWK_LIBZIP_zip_0100_zip1file
141 * @tc.name: zip_0100_zip1file
142 * @tc.desc:
143 */
144 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_unzip_0100_zip1file, Function | MediumTest | Level1)
145 {
146 std::string src = BASE_PATH + APP_PATH + "result/zip1file.zip";
147 std::string dest = BASE_PATH + APP_PATH + "unzip/zip1file";
148
149 OPTIONS options;
150 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
151 Unzip(src, dest, options, zlibCallbackInfo);
152 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
153 }
154
155 /**
156 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0100
157 * @tc.name: Checkzip_0100
158 * @tc.desc:
159 */
160 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0100, Function | MediumTest | Level1)
161 {
162 std::string src = BASE_PATH + APP_PATH + "test";
163 std::string dest = BASE_PATH + APP_PATH + "check";
164 FilePath destFile(dest);
165
166 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
167 Zip(src, dest, false, zlibCallbackInfo);
168 destFile.CheckDestDirTail();
169 FilePath newDestFile(destFile.CheckDestDirTail());
170 std::cout << newDestFile.Value() << std::endl;
171 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
172 }
173
174 /**
175 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0200
176 * @tc.name: Checkzip_0200
177 * @tc.desc:
178 */
179 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0200, Function | MediumTest | Level1)
180 {
181 std::string src = BASE_PATH + APP_PATH + "test";
182 std::string dest = BASE_PATH + APP_PATH + "error/check.zip";
183
184 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
185 Zip(src, dest, false, zlibCallbackInfo);
186 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
187 }
188
189 /**
190 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0300
191 * @tc.name: Checkzip_0300
192 * @tc.desc:
193 */
194 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0300, Function | MediumTest | Level1)
195 {
196 std::string src = BASE_PATH + APP_PATH + "error";
197 std::string src1 = BASE_PATH + APP_PATH + "#%#@$%";
198 std::string src2 = BASE_PATH + APP_PATH + "error/error1";
199 std::string dest = BASE_PATH + APP_PATH + "/check.zip";
200
201 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
202 Zip(src, dest, false, zlibCallbackInfo);
203 Zip(src1, dest, false, zlibCallbackInfo);
204 Zip(src2, dest, false, zlibCallbackInfo);
205 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
206 }
207
208 /**
209 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0400
210 * @tc.name: Checkzip_0400
211 * @tc.desc:
212 */
213 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0400, Function | MediumTest | Level1)
214 {
215 std::string src1 = BASE_PATH + APP_PATH + "error.txt";
216 std::string dest = BASE_PATH + APP_PATH + "check.zip";
217 FilePath srcFile1(src1);
218
219 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
220 Zip(src1, dest, false, zlibCallbackInfo);
221 std::cout << "srcFile1 DirName: " << srcFile1.DirName().Value() << std::endl;
222 std::cout << "srcFile1 Value: " << srcFile1.Value() << std::endl;
223 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
224 }
225
226 /**
227 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0500
228 * @tc.name: Checkzip_0500
229 * @tc.desc:
230 */
231 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0500, Function | MediumTest | Level1)
232 {
233 std::string src = BASE_PATH + APP_PATH + "error";
234 std::string dest = BASE_PATH + APP_PATH + "error1";
235
236 OPTIONS options;
237 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
238 Unzip(src, dest, options, zlibCallbackInfo);
239 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
240 }
241
242 /**
243 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0600
244 * @tc.name: Checkzip_0600
245 * @tc.desc:
246 */
247 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0600, Function | MediumTest | Level1)
248 {
249 std::string src = BASE_PATH + APP_PATH + "test";
250 std::string dest = "";
251
252 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
253 Zip(src, dest, false, zlibCallbackInfo);
254 std::cout << dest << std::endl;
255 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
256 }
257
258 /**
259 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0700
260 * @tc.name: Checkzip_0700
261 * @tc.desc:
262 */
263 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0700, Function | MediumTest | Level1)
264 {
265 std::string src = "";
266 std::string dest = BASE_PATH + APP_PATH;
267 FilePath destFile(dest);
268
269 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
270 Zip(src, dest, false, zlibCallbackInfo);
271 destFile.CheckDestDirTail();
272 FilePath newDestFile(destFile.CheckDestDirTail());
273 std::cout << newDestFile.Value() << std::endl;
274 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
275 }
276
277 /**
278 * @tc.number: APPEXECFWK_LIBZIP_Checkzip_0800
279 * @tc.name: Checkzip_0800
280 * @tc.desc:
281 */
282 HWTEST_F(ZipTest, APPEXECFWK_LIBZIP_Checkzip_0800, Function | MediumTest | Level1)
283 {
284 std::string src = "";
285 std::string dest = BASE_PATH + APP_PATH;
286
287 OPTIONS options;
288 std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo = std::make_shared<ZlibCallbackInfo>();
289 Unzip(src, dest, options, zlibCallbackInfo);
290 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
291 }
292 } // namespace LIBZIP
293 } // namespace AppExecFwk
294 } // namespace OHOS
295