actszipfileandunzipfiletest.test.js 128.6 KB
Newer Older
K
kirl75 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import zlib from '@ohos.zlib'
import fileio from '@ohos.fileio'
R
renyi 已提交
18
import featureAbility from '@ohos.ability.featureAbility'
I
inter515 已提交
19
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, Level } from '@ohos/hypium'
J
jiyong_sd 已提交
20

I
inter515 已提交
21 22 23
let dir = "";
let infos = "";
let SRC_FILE_INVALID = 900001;
I
inter515 已提交
24
let OUTPUT_FILE_INVALID = 900002;
I
inter515 已提交
25
let PARAM_ERROR = 401;
I
add xts  
inter515 已提交
26

J
jiyong_sd 已提交
27
export default function ActsZlibTest() {
I
add xts  
inter515 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40
    describe('ActsZlibTest', function () {
        beforeEach(async (done) => {
            var context = featureAbility.getContext();
            context.getCacheDir((err, data) => {
                console.info('ActsZlibTest successful. Data:' + JSON.stringify(data));
                dir = data;
                var objectone = "com.example.amsZipfileUnzipfileST.MainAbility/com.example.amsZipfileUnzipfileST/";
                var objecttwo = "com.example.amsZipfileUnzipfileST.MainAbility/com.example.amsZipfileUnzipfileST/zipunzip";
                var objectthree = "com.example.amsZipfileUnzipfileST.MainAbility/ActsZlibTest/example.amsZipfileUnzipfileST";
                infos = dir + objectone + objecttwo + objectthree;
                done();
            })
        });
K
kirl75 已提交
41

I
add xts  
inter515 已提交
42 43 44 45 46 47
        /*
        * @tc.number: ACTS_ZipFile_0100
        * @tc.name: zipFile
        * @tc.desc: inFile is empty
        */
        it('ACTS_ZipFile_0100', 0, async function (done) {
I
inter515 已提交
48
            console.info("==================ACTS_ZipFile_0100 start==================");
I
add xts  
inter515 已提交
49 50 51 52 53
            var path = "";
            var zipDest = dir + "/ACTS_ZipFile_0100.zip"
            var options = {};
            options.level = zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION;
            zlib.zipFile(path, zipDest, options).then((data) => {
I
inter515 已提交
54
                console.info("ACTS_ZipFile_0100 data: " + data);
I
add xts  
inter515 已提交
55 56 57
                expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                done();
            }).catch((err) => {
I
inter515 已提交
58
                console.info("ACTS_ZipFile_0100 zipFile fail: " + err);
I
add xts  
inter515 已提交
59 60 61
                expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                done();
            })
I
inter515 已提交
62
            console.info("==================ACTS_ZipFile_0100 end==================");
I
add xts  
inter515 已提交
63
        })
K
kirl75 已提交
64

I
add xts  
inter515 已提交
65 66 67 68 69 70
        /*
        * @tc.number: ACTS_ZipFile_0200
        * @tc.name: zipFile
        * @tc.desc: inFile doesn't exist
        */
        it('ACTS_ZipFile_0200', 0, async function (done) {
I
inter515 已提交
71
            console.info("==================ACTS_ZipFile_0200 start==================");
I
add xts  
inter515 已提交
72 73 74 75 76 77 78 79
            var path = dir + "/ACTS_ZipFile_9999900.txt";
            var src = dir + "/ACTS_ZipFile_999991100.txt";
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_0200 write data to file successfully:" + number);
                var options = {};
                options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION;
                zlib.zipFile(src, dir, options).then((data) => {
I
inter515 已提交
80
                    console.info("ACTS_ZipFile_0200 data: " + data);
I
add xts  
inter515 已提交
81 82 83
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
I
inter515 已提交
84
                    console.info("ACTS_ZipFile_0200 zipFile fail: " + err);
I
add xts  
inter515 已提交
85 86 87 88 89 90 91 92
                    expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_0200 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
93
            console.info("==================ACTS_ZipFile_0200 end==================");
I
add xts  
inter515 已提交
94
        })
K
kirl75 已提交
95

I
add xts  
inter515 已提交
96 97 98 99 100 101
        /*
        * @tc.number: ACTS_ZipFile_0300
        * @tc.name: zipFile
        * @tc.desc: output file not specified
        */
        it('ACTS_ZipFile_0300', 0, async function (done) {
I
inter515 已提交
102
            console.info("==================ACTS_ZipFile_0300 start==================");
I
add xts  
inter515 已提交
103 104 105 106 107 108 109 110
            var path = dir + "/ACTS_ZipFile_0300.txt";
            var zipDest = "";
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_0300 write data to file successfully:" + number);
                var options = {};
                options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION;
                zlib.zipFile(path, zipDest, options).then((data) => {
I
inter515 已提交
111
                    console.info("ACTS_ZipFile_0300 data: " + data);
I
add xts  
inter515 已提交
112 113 114
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
I
inter515 已提交
115
                    console.info("ACTS_ZipFile_0300 zipFile fail: " + err);
I
add xts  
inter515 已提交
116 117 118 119 120 121 122 123
                    expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_0300 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
124
            console.info("==================ACTS_ZipFile_0300 end==================");
I
add xts  
inter515 已提交
125
        })
K
kirl75 已提交
126

I
add xts  
inter515 已提交
127 128 129 130 131 132
        /*
        * @tc.number: ACTS_ZipFile_0400
        * @tc.name: zipFile
        * @tc.desc: The output file is a directory that does not exist
        */
        it('ACTS_ZipFile_0400', 0, async function (done) {
I
inter515 已提交
133
            console.info("==================ACTS_ZipFile_0400 start==================");
I
add xts  
inter515 已提交
134 135 136 137 138 139 140 141
            var path = dir + "/ACTS_ZipFile_0400.txt";
            var zipDest = "/ACTS_ZipFile_0400.zip";
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_0400 write data to file successfully:" + number);
                var options = {};
                options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION;
                zlib.zipFile(path, zipDest, options).then((data) => {
I
inter515 已提交
142
                    console.info("ACTS_ZipFile_0400 data: " + data);
I
add xts  
inter515 已提交
143 144 145
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
I
inter515 已提交
146
                    console.info("ACTS_ZipFile_0400 zipFile fail: " + err);
I
add xts  
inter515 已提交
147 148 149 150 151 152 153 154
                    expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_0400 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
155
            console.info("==================ACTS_ZipFile_0400 end==================");
I
add xts  
inter515 已提交
156
        })
K
kirl75 已提交
157

I
add xts  
inter515 已提交
158 159 160 161 162 163
        /*
        * @tc.number: ACTS_ZipFile_2200
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_NO_COMPRESSION,
        */
        it('ACTS_ZipFile_2200', 0, async function (done) {
I
inter515 已提交
164
            console.info("==================ACTS_ZipFile_2200 start==================");
I
add xts  
inter515 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
            var path = dir + "/ACTS_ZipFile_2200.txt";
            var zipDest = dir + "/ACTS_ZipFile_2200.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2200";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2200.txt";
            var options = {};
            options.level = zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2200 write data to file secondlly successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2200 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2200 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
196
                            console.info("ACTS_ZipFile_2200 err: " + err);
I
add xts  
inter515 已提交
197 198 199 200 201 202 203 204 205
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2200 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
206
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
207 208 209 210 211 212 213 214
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2200 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
215
            console.info("==================ACTS_ZipFile_2200 end==================");
R
renyi 已提交
216
        });
K
kirl75 已提交
217

I
add xts  
inter515 已提交
218 219 220 221 222 223
        /*
        * @tc.number: ACTS_ZipFile_2300
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_BEST_SPEED,
        */
        it('ACTS_ZipFile_2300', 0, async function (done) {
I
inter515 已提交
224
            console.info("==================ACTS_ZipFile_2300 start==================");
I
add xts  
inter515 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
            var path = dir + "/ACTS_ZipFile_2300.txt";
            var zipDest = dir + "/ACTS_ZipFile_2300.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2300";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2300.txt";
            var options = {};
            options.level = zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2300 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2300 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2300 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
256
                            console.info("ACTS_ZipFile_2300 err: " + err);
I
add xts  
inter515 已提交
257 258 259 260 261 262 263 264 265
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2300 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
266
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
267 268 269 270 271 272 273 274
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2300 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
275
            console.info("==================ACTS_ZipFile_2300 end==================");
I
add xts  
inter515 已提交
276
        })
K
kirl75 已提交
277

I
add xts  
inter515 已提交
278 279 280 281 282 283
        /*
        * @tc.number: ACTS_ZipFile_2400
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_BEST_COMPRESSION,
        */
        it('ACTS_ZipFile_2400', 0, async function (done) {
I
inter515 已提交
284
            console.info("==================ACTS_ZipFile_2400 start==================");
I
add xts  
inter515 已提交
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
            var path = dir + "/ACTS_ZipFile_2400.txt";
            var zipDest = dir + "/ACTS_ZipFile_2400.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2400";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2400.txt";
            var options = {};
            options.level = zlib.CompressLevel.COMPRESS_LEVEL_BEST_COMPRESSION;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2400 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2400 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2400 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
316
                            console.info("ACTS_ZipFile_2400 err: " + err);
I
add xts  
inter515 已提交
317 318 319 320 321 322 323 324 325
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2400 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
326
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
327 328 329 330 331 332 333 334
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2400 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
335
            console.info("==================ACTS_ZipFile_2400 end==================");
R
renyi 已提交
336
        });
K
kirl75 已提交
337

I
add xts  
inter515 已提交
338 339 340 341 342 343
        /*
        * @tc.number: ACTS_ZipFile_2500
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_DEFAULT_COMPRESSION,
        */
        it('ACTS_ZipFile_2500', 0, async function (done) {
I
inter515 已提交
344
            console.info("==================ACTS_ZipFile_2500 start==================");
I
add xts  
inter515 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
            var path = dir + "/ACTS_ZipFile_2500.txt";
            var zipDest = dir + "/ACTS_ZipFile_2500.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2500";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2500.txt";
            var options = {};
            options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2500 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2500 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2500 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
376
                            console.info("ACTS_ZipFile_2500 err: " + err);
I
add xts  
inter515 已提交
377 378 379 380 381 382 383 384 385
                            expect(err).assertFail();
                            done()
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2500 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
386
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
387 388 389 390 391 392 393 394
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2500 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
395
            console.info("==================ACTS_ZipFile_2500 end==================");
R
renyi 已提交
396
        });
K
kirl75 已提交
397

I
add xts  
inter515 已提交
398 399 400 401 402 403
        /*
        * @tc.number: ACTS_ZipFile_2600
        * @tc.name: zipFile
        * @tc.desc: MEM_LEVEL_MIN_MEMLEVEL,,
        */
        it('ACTS_ZipFile_2600', 0, async function (done) {
I
inter515 已提交
404
            console.info("==================ACTS_ZipFile_2600 start==================");
I
add xts  
inter515 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
            var path = dir + "/ACTS_ZipFile_2600.txt";
            var zipDest = dir + "/ACTS_ZipFile_2600.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2600";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2600.txt";
            var options = {};
            options.memLevel = zlib.MemLevel.MEM_LEVEL_MIN;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2600 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2600 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2600 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
436
                            console.info("ACTS_ZipFile_2600 err: " + err);
I
add xts  
inter515 已提交
437 438 439 440 441 442 443 444 445
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2600 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
446
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
447 448 449 450 451 452 453 454
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2600 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
455
            console.info("==================ACTS_ZipFile_2600 end==================");
R
renyi 已提交
456
        });
K
kirl75 已提交
457

I
add xts  
inter515 已提交
458 459 460 461 462 463
        /*
        * @tc.number: ACTS_ZipFile_2700
        * @tc.name: zipFile
        * @tc.desc: MEM_LEVEL_MAX_MEMLEVEL,,
        */
        it('ACTS_ZipFile_2700', 0, async function (done) {
I
inter515 已提交
464
            console.info("==================ACTS_ZipFile_2700 start==================");
I
add xts  
inter515 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
            var path = dir + "/ACTS_ZipFile_2700.txt";
            var zipDest = dir + "/ACTS_ZipFile_2700.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2700";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2700.txt";
            var options = {};
            options.memLevel = zlib.MemLevel.MEM_LEVEL_MAX;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2700 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2700 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2700 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
496
                            console.info("ACTS_ZipFile_2700 err: " + err);
I
add xts  
inter515 已提交
497 498 499 500 501 502 503 504 505
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2700 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
506
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
507 508 509 510 511 512 513 514
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2700 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
515
            console.info("==================ACTS_ZipFile_2700 end==================");
R
renyi 已提交
516
        });
K
kirl75 已提交
517

I
add xts  
inter515 已提交
518 519 520 521 522 523
        /*
        * @tc.number: ACTS_ZipFile_2800
        * @tc.name: zipFile
        * @tc.desc: MEM_LEVEL_DEFAULT_MEMLEVEL,,
        */
        it('ACTS_ZipFile_2800', 0, async function (done) {
I
inter515 已提交
524
            console.info("==================ACTS_ZipFile_2800 start==================");
I
add xts  
inter515 已提交
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
            var path = dir + "/ACTS_ZipFile_2800.txt";
            var zipDest = dir + "/ACTS_ZipFile_2800.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2800";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2800.txt";
            var options = {};
            options.memLevel = zlib.MemLevel.MEM_LEVEL_DEFAULT;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2800 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2800 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2800 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
556
                            console.info("ACTS_ZipFile_2800 err: " + err);
I
add xts  
inter515 已提交
557 558 559 560 561 562 563 564 565
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2800 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
566
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
567 568 569 570 571 572 573 574
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2800 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
575
            console.info("==================ACTS_ZipFile_2800 end==================");
R
renyi 已提交
576
        });
K
kirl75 已提交
577

I
add xts  
inter515 已提交
578 579 580 581 582 583
        /*
        * @tc.number: ACTS_ZipFile_2900
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_DEFAULT_STRATEGY,,
        */
        it('ACTS_ZipFile_2900', 0, async function (done) {
I
inter515 已提交
584
            console.info("==================ACTS_ZipFile_2900 start==================");
I
add xts  
inter515 已提交
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
            var path = dir + "/ACTS_ZipFile_2900.txt";
            var zipDest = dir + "/ACTS_ZipFile_2900.zip"
            var unzipdir = dir + "/ACTS_ZipFile_2900";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_2900.txt";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_2900 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_2900 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_2900 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
616
                            console.info("ACTS_ZipFile_2900 err: " + err);
I
add xts  
inter515 已提交
617 618 619 620 621 622 623 624 625
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2900 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
626
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
627 628 629 630 631 632 633 634
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2900 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
635
            console.info("==================ACTS_ZipFile_2900 end==================");
I
add xts  
inter515 已提交
636
        });
K
kirl75 已提交
637

I
add xts  
inter515 已提交
638 639 640 641 642 643
        /*
        * @tc.number: ACTS_ZipFile_3000
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FILTERED,,
        */
        it('ACTS_ZipFile_3000', 0, async function (done) {
I
inter515 已提交
644
            console.info("==================ACTS_ZipFile_3000 start==================");
I
add xts  
inter515 已提交
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
            var path = dir + "/ACTS_ZipFile_3000.txt";
            var zipDest = dir + "/ACTS_ZipFile_3000.zip"
            var unzipdir = dir + "/ACTS_ZipFile_3000";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_3000.txt";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_3000 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_3000 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_3000 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
676
                            console.info("ACTS_ZipFile_3000 err: " + err);
I
add xts  
inter515 已提交
677 678 679 680 681 682 683 684 685
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3000 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
686
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
687 688 689 690 691 692 693 694
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3000 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
695
            console.info("==================ACTS_ZipFile_3000 end==================");
R
renyi 已提交
696
        });
K
kirl75 已提交
697

I
add xts  
inter515 已提交
698 699 700 701 702 703
        /*
        * @tc.number: ACTS_ZipFile_3100
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_HUFFMAN_ONLY,,
        */
        it('ACTS_ZipFile_3100', 0, async function (done) {
I
inter515 已提交
704
            console.info("==================ACTS_ZipFile_3100 start==================");
I
add xts  
inter515 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
            var path = dir + "/ACTS_ZipFile_3100.txt";
            var zipDest = dir + "/ACTS_ZipFile_3100.zip"
            var unzipdir = dir + "/ACTS_ZipFile_3100";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_3100.txt";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_HUFFMAN_ONLY;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_3100 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_3100 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_3100 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
736
                            console.info("ACTS_ZipFile_3100 err: " + err);
I
add xts  
inter515 已提交
737 738 739 740 741 742 743 744 745
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3100 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
746
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
747 748 749 750 751 752 753 754
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3100 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
755
            console.info("==================ACTS_ZipFile_3100 end==================");
R
renyi 已提交
756
        });
K
kirl75 已提交
757

I
add xts  
inter515 已提交
758 759 760 761 762 763
        /*
        * @tc.number: ACTS_ZipFile_3200
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_RLE,,
        */
        it('ACTS_ZipFile_3200', 0, async function (done) {
I
inter515 已提交
764
            console.info("==================ACTS_ZipFile_3200 start==================");
I
add xts  
inter515 已提交
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
            var path = dir + "/ACTS_ZipFile_3200.txt";
            var zipDest = dir + "/ACTS_ZipFile_3200.zip";
            var unzipdir = dir + "/ACTS_ZipFile_3200";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_3200.txt";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_RLE;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_3200 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_3200 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_3200 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
796
                            console.info("ACTS_ZipFile_3200 err: " + err);
I
add xts  
inter515 已提交
797 798 799 800 801 802 803 804 805 806
                            done();
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3200 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
807
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
808 809 810 811 812 813 814 815
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3200 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
816
            console.info("==================ACTS_ZipFile_3200 end==================");
R
renyi 已提交
817
        });
K
kirl75 已提交
818

I
add xts  
inter515 已提交
819 820 821 822 823 824
        /*
        * @tc.number: ACTS_ZipFile_3300
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FIXED,,
        */
        it('ACTS_ZipFile_3300', 0, async function (done) {
I
inter515 已提交
825
            console.info("==================ACTS_ZipFile_3300 start==================");
I
add xts  
inter515 已提交
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
            var path = dir + "/ACTS_ZipFile_3300.txt";
            var zipDest = dir + "/ACTS_ZipFile_3300.zip"
            var unzipdir = dir + "/ACTS_ZipFile_3300";
            var unzipresultfile = unzipdir + "/ACTS_ZipFile_3300.txt";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_3300 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_3300 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then((data) => {
                            var unzipStat = fileio.statSync(unzipresultfile);
                            var isFile = unzipStat.isFile();
                            expect(isFile).assertTrue();
                            var destSize = unzipStat.size;
                            var originSize = fileio.statSync(path).size;
                            var result = (originSize == destSize);
                            expect(result).assertTrue();
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            console.error('ACTS_ZipFile_3300 unzipFile');
                            done();
                        }).catch((err) => {
I
inter515 已提交
857
                            console.info("ACTS_ZipFile_3300 err: " + err);
I
add xts  
inter515 已提交
858 859 860 861 862 863 864 865 866
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3300 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
867
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
868 869 870 871 872 873 874 875
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3300 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
876
            console.info("==================ACTS_ZipFile_3300 end==================");
R
renyi 已提交
877
        });
K
kirl75 已提交
878

I
add xts  
inter515 已提交
879 880 881 882 883 884
        /*
        * @tc.number: ACTS_ZipFile_3500
        * @tc.name: zipFile
        * @tc.desc: INPUT_FILE_NOT_EXIST,,
        */
        it('ACTS_ZipFile_3500', 0, async function (done) {
I
inter515 已提交
885
            console.info("==================ACTS_ZipFile_3500 start==================");
I
add xts  
inter515 已提交
886 887 888 889 890 891 892 893 894
            var path = dir + "/ACTS_ZipFile_3500.txt";
            var src = dir + "/ACTS_ZipFile_9900.txt";
            var unzipdir = dir + "/ACTS_ZipFile_3500";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_3500 write  successfully:" + number);
                zlib.zipFile(src, dir, options).then((data) => {
I
inter515 已提交
895
                    console.info("ACTS_ZipFile_3500 data: " + data);
I
add xts  
inter515 已提交
896 897 898
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
I
inter515 已提交
899
                    console.info("ACTS_ZipFile_3500 err: " + err);
I
add xts  
inter515 已提交
900 901 902 903 904 905 906 907
                    expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                });
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3500 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
908
            console.info("==================ACTS_ZipFile_3500 end ==================");
I
add xts  
inter515 已提交
909
        })
K
kirl75 已提交
910

I
add xts  
inter515 已提交
911 912 913 914 915 916
        /*
        * @tc.number: ACTS_ZipFile_3600
        * @tc.name: zipFile
        * @tc.desc: INPUT_FILE_NULL,,
        */
        it('ACTS_ZipFile_3600', 0, async function (done) {
I
inter515 已提交
917
            console.info("==================ACTS_ZipFile_3600 start==================");
I
add xts  
inter515 已提交
918 919 920 921 922 923 924 925
            var path = dir + "/ACTS_ZipFile_3600.txt";
            var zipDest = "";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_3600 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
I
inter515 已提交
926
                    console.info("ACTS_ZipFile_3600 data: " + data);
I
add xts  
inter515 已提交
927 928 929
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
I
inter515 已提交
930
                    console.info("ACTS_ZipFile_3600 err: " + err);
I
add xts  
inter515 已提交
931 932 933 934 935 936 937 938
                    expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                });
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3600 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
939
            console.info("==================ACTS_ZipFile_3600 end ==================")
I
add xts  
inter515 已提交
940
        })
K
kirl75 已提交
941

I
add xts  
inter515 已提交
942 943 944 945 946 947
        /*
        * @tc.number: ACTS_ZipFile_4500
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FILTERED_CALLBACK,,
        */
        it('ACTS_ZipFile_4500', 0, async function (done) {
I
inter515 已提交
948
            console.info("==================ACTS_ZipFile_4500 start==================");
I
add xts  
inter515 已提交
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
            var path = dir + "/ACTS_ZipFile_4500.txt";
            var zipDest = dir + "/ACTS_ZipFile_4500.zip"
            var unzipDest = dir + "/ACTS_ZipFile_9900.zip"
            var unzipdir = dir + "/ACTS_ZipFile_4500";
            var zipdir = dir + "/ACTS_ZipFile_9900";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_4500 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then((data) => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_4500 mkdir successfully");
                        zlib.unzipFile(unzipDest, zipdir, options).then((data) => {
I
inter515 已提交
970
                            console.info("ACTS_ZipFile_4500 data: " + data);
I
add xts  
inter515 已提交
971 972 973
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                            done();
                        }).catch((err) => {
I
inter515 已提交
974
                            console.info("ACTS_ZipFile_4500 err: " + err);
I
add xts  
inter515 已提交
975 976 977 978 979 980 981 982 983
                            expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_4500 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
I
inter515 已提交
984
                    console.info("ACTS_ZipFile_4500 zipFile fail: " + err);
I
add xts  
inter515 已提交
985 986 987 988 989 990 991 992
                    expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_4500 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
993
            console.info("==================ACTS_ZipFile_4500 end==================");
I
add xts  
inter515 已提交
994 995 996 997 998 999 1000 1001
        })

        /*
        * @tc.number: ACTS_ZipFile_4900
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FILTERED_PROMISE,
        */
        it('ACTS_ZipFile_4900', 0, async function (done) {
I
inter515 已提交
1002
            console.info("==================ACTS_ZipFile_4900 start==================");
I
add xts  
inter515 已提交
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
            var path = dir + "/ACTS_ZipFile_4900.txt";
            var zipDest = dir + "/ACTS_ZipFile_4900.zip"
            var unzipDest = dir + "/ACTS_ZipFile_4900.zip"
            var unzipdir = dir + "/ACTS_ZipFile_4900";
            var zipdir = dir + "/ACTS_ZipFile_4900";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_4900 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then(data => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_4900 mkdir successfully");
                        zlib.unzipFile(unzipDest, zipdir, options).then(data => {
I
inter515 已提交
1024
                            console.info("ACTS_ZipFile_4900 data: " + data);
I
add xts  
inter515 已提交
1025 1026 1027
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            done();
                        }).catch(err => {
I
inter515 已提交
1028
                            console.info("ACTS_ZipFile_4900 err: " + err);
I
add xts  
inter515 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_4900 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch(err => {
I
inter515 已提交
1038
                    console.info("ACTS_ZipFile_4900 zipFile fail: " + err);
I
add xts  
inter515 已提交
1039 1040 1041 1042 1043 1044 1045 1046
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_4900 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
1047
            console.info("==================ACTS_ZipFile_4900 end==================");
I
add xts  
inter515 已提交
1048 1049 1050 1051 1052 1053 1054 1055
        })

        /*
        * @tc.number: ACTS_ZipFile_5000
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FIXED,
        */
        it('ACTS_ZipFile_5000', 0, async function (done) {
I
inter515 已提交
1056
            console.info("==================ACTS_ZipFile_5000 start==================");
I
add xts  
inter515 已提交
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
            var path = dir + "/ACTS_ZipFile_5000.txt";
            var zipDest = dir + "/ACTS_ZipFile_5000.zip"
            var unzipdir = dir + "/ACTS_ZipFile_5000";
            var options = {};
            options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED;
            var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            fileio.write(fd, infos).then(function (number) {
                console.info("ACTS_ZipFile_5000 write data to file successfully:" + number);
                zlib.zipFile(path, zipDest, options).then(data => {
                    var zipStat = fileio.statSync(zipDest);
                    var isFile = zipStat.isFile();
                    expect(isFile).assertTrue();
                    var srcSize = fileio.statSync(path).size;
                    var destSize = zipStat.size;
                    expect(srcSize > destSize).assertTrue();
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                    fileio.mkdir(unzipdir).then(function () {
                        console.info("ACTS_ZipFile_5000 mkdir successfully");
                        zlib.unzipFile(zipDest, unzipdir, options).then(data => {
I
inter515 已提交
1076
                            console.info("ACTS_ZipFile_5000 data: " + data);
I
add xts  
inter515 已提交
1077 1078 1079
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            done();
                        }).catch(err => {
I
inter515 已提交
1080
                            console.info("unzipFile fail: " + err);
I
add xts  
inter515 已提交
1081 1082 1083 1084 1085 1086 1087 1088 1089
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_5000 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch(err => {
I
inter515 已提交
1090
                    console.info("zipFile fail: " + err);
I
add xts  
inter515 已提交
1091 1092 1093 1094 1095 1096 1097 1098
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_5000 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
I
inter515 已提交
1099
            console.info("==================ACTS_ZipFile_5000 end==================");
I
add xts  
inter515 已提交
1100 1101
        })

I
inter515 已提交
1102 1103 1104 1105 1106 1107
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0076
        * @tc.name: compressFileOfFolders
        * @tc.desc: test compressFile when input is folders
        */
        it('compressFileOfFolders', Level.LEVEL2, async function (done) {
I
inter515 已提交
1108
            console.info("==================compressFileOfFolders start==================");
I
inter515 已提交
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
            let inputPath1 = dir + "/compressFileOfFolders1";
            let inputPath2 = dir + "/compressFileOfFolders2";
            let path1 = inputPath1 + "/compressFileOfFolders1.txt";
            let zipDest1 = dir + "/compressFileOfFolders1.zip";
            let path2 = inputPath2 + "/compressFileOfFolders2.txt";
            let zipDest2 = dir + "/compressFileOfFolders2.zip";
            fileio.mkdirSync(inputPath1);
            fileio.mkdirSync(inputPath2);
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("compressFileOfFolders write data to file successfully :" + number);
            }).catch(function (err) {
                console.info("compressFileOfFolders write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            console.info("compressFileOfFolders start compressFile");
            await zlib.compressFile(inputPath1, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then((data) => {
                console.info("compressFileOfFolders data: " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path1).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch((err) => {
                console.info("compressFileOfFolders data: " + JSON.stringify(err));
                expect(err).assertFail();
            })
            let fd2 = fileio.openSync(path2, 0o100 | 0o2, 0o666);
            await fileio.write(fd2, infos).then(function (number) {
                console.info("compressFileOfFolders write data to file successfully :" + number);
            }).catch(function (err) {
                console.info("compressFileOfFolders write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            zlib.compressFile(inputPath2, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("compressFileOfFolders data2: " + JSON.stringify(data));
                console.info("compressFileOfFolders err2: " + JSON.stringify(err));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path2).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })

I
add xts  
inter515 已提交
1164
        /*
I
inter515 已提交
1165 1166 1167
        * @tc.number: SUB_BMS_TOOL_ZLIB_0077
        * @tc.name: compressFileTest
        * @tc.desc: test compressFile when inFile and out file is valid
I
add xts  
inter515 已提交
1168
        */
I
inter515 已提交
1169
        it('compressFileTest', Level.LEVEL2, async function (done) {
I
inter515 已提交
1170
            console.info("==================compressFileTest start==================");
I
inter515 已提交
1171 1172 1173 1174
            let path1 = dir + "/compressFileTest1.txt";
            let zipDest1 = dir + "/compressFileTest1.zip";
            let path2 = dir + "/compressFileTest2.txt";
            let zipDest2 = dir + "/compressFileTest2.zip";
I
add xts  
inter515 已提交
1175 1176
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
I
inter515 已提交
1177
                console.info("compressFileTest write data to file successfully :" + number);
I
add xts  
inter515 已提交
1178
            }).catch(function (err) {
I
inter515 已提交
1179
                console.info("compressFileTest write data to file failed with error:" + err);
I
add xts  
inter515 已提交
1180 1181
                expect(err).assertFail();
            });
I
inter515 已提交
1182
            console.info("compressFileTest start compressFile");
I
add xts  
inter515 已提交
1183 1184 1185
            await zlib.compressFile(path1, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then((data) => {
I
inter515 已提交
1186
                console.info("compressFileTest data: " + JSON.stringify(data));
I
add xts  
inter515 已提交
1187 1188 1189 1190 1191 1192 1193
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path1).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
K
kirl75 已提交
1194
            }).catch((err) => {
I
inter515 已提交
1195
                console.info("compressFileTest data: " + JSON.stringify(err));
I
add xts  
inter515 已提交
1196
                expect(err).assertFail();
K
kirl75 已提交
1197
            })
I
add xts  
inter515 已提交
1198 1199
            let fd2 = fileio.openSync(path2, 0o100 | 0o2, 0o666);
            await fileio.write(fd2, infos).then(function (number) {
I
inter515 已提交
1200
                console.info("compressFileTest write data to file successfully :" + number);
I
add xts  
inter515 已提交
1201
            }).catch(function (err) {
I
inter515 已提交
1202
                console.info("compressFileTest write data to file failed with error:" + err);
I
add xts  
inter515 已提交
1203 1204 1205 1206 1207
                expect(err).assertFail();
            });
            zlib.compressFile(path2, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
I
inter515 已提交
1208 1209
                console.info("compressFileTest data2: " + JSON.stringify(data));
                console.info("compressFileTest err2: " + JSON.stringify(err));
I
add xts  
inter515 已提交
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path2).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })
1221

I
add xts  
inter515 已提交
1222
        /*
I
inter515 已提交
1223 1224 1225
        * @tc.number: SUB_BMS_TOOL_ZLIB_0078
        * @tc.name: compressFileInFileNotExist
        * @tc.desc: test compressFile when inFile is not exist
I
add xts  
inter515 已提交
1226
        */
I
inter515 已提交
1227
        it('compressFileInFileNotExist', Level.LEVEL3, async function (done) {
I
inter515 已提交
1228
            console.info("==================compressFileInFileNotExist start==================");
I
inter515 已提交
1229 1230
            let path = "nonexist.txt";
            let zipDest = dir + "/compressFileInFileNotExist.zip";
I
add xts  
inter515 已提交
1231 1232 1233
            await zlib.compressFile(path, zipDest, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
            }).then((data) => {
I
inter515 已提交
1234
                console.info("compressFileInFileNotExist invalid src file success!");
I
add xts  
inter515 已提交
1235 1236 1237
                expect(data).assertFail();
                done();
            }).catch((err) => {
I
inter515 已提交
1238
                console.info("compressFileInFileNotExist zipFile fail: " + JSON.stringify(err));
I
inter515 已提交
1239 1240 1241 1242 1243 1244
                expect(err.code).assertEqual(SRC_FILE_INVALID);
                done();
            })
            zlib.compressFile(path, zipDest, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
            }, (err, data) => {
I
add xts  
inter515 已提交
1245
                expect(err.code).assertEqual(SRC_FILE_INVALID);
I
inter515 已提交
1246
                expect(data).assertEqual(undefined);
I
add xts  
inter515 已提交
1247 1248
                done();
            })
I
inter515 已提交
1249
            console.info("==================compressFileInFileNotExist end==================");
I
add xts  
inter515 已提交
1250
        })
1251

I
add xts  
inter515 已提交
1252
        /*
I
inter515 已提交
1253 1254 1255 1256
        * @tc.number: SUB_BMS_TOOL_ZLIB_0079
        * @tc.name: compressFileInFileNull
        * @tc.desc: test compressFile when inFile is null
        */
I
inter515 已提交
1257
        it('compressFileInFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1258
            console.info("==================compressFileInFileNull start==================");
I
inter515 已提交
1259
            let zipDest = dir + "/compressFileInFileNull.zip";
I
inter515 已提交
1260
            try {
I
inter515 已提交
1261 1262 1263
                await zlib.compressFile(null, zipDest, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }).then((data) => {
I
inter515 已提交
1264
                    console.info("compressFileInFileNull invalid src file success!");
I
inter515 已提交
1265 1266
                    expect().assertFail();
                }).catch((err) => {
I
inter515 已提交
1267
                    console.info("compressFileInFileNull zipFile fail: " + JSON.stringify(err));
I
inter515 已提交
1268 1269
                    expect().assertFail();
                })
I
inter515 已提交
1270
            } catch (err) {
I
inter515 已提交
1271 1272
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1273
            try {
I
inter515 已提交
1274 1275 1276
                zlib.compressFile(null, zipDest, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }, (err, data) => {
I
inter515 已提交
1277
                    console.info("compressFile result");
I
inter515 已提交
1278 1279 1280
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1281
            } catch (err) {
I
inter515 已提交
1282 1283 1284
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
I
inter515 已提交
1285
            console.info("==================compressFileInFileNull end==================");
I
inter515 已提交
1286 1287
        })

I
inter515 已提交
1288 1289 1290 1291 1292 1293
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0080
        * @tc.name: compressFileOutFileNotExist
        * @tc.desc: test compressFile when outFile is not existed.
        */
        it('compressFileOutFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1294
            console.info("==================compressFileOutFileNull start==================");
I
inter515 已提交
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
            let path1 = dir + "/compressFileOutFileNull.txt";
            let outFile = "/11111/22222.zip";
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("fileio write data to file successfully :" + number);
            }).catch(function (err) {
                console.info("fileio write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path1, outFile, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
            }).then((data) => {
I
inter515 已提交
1307
                console.info("compressFileOutFileNull invalid src file success!");
I
inter515 已提交
1308 1309
                expect().assertFail();
            }).catch((err) => {
I
inter515 已提交
1310
                console.info("compressFileOutFileNull zipFile fail: " + JSON.stringify(err));
I
inter515 已提交
1311 1312 1313 1314 1315 1316
                expect(err.code).assertEqual(OUTPUT_FILE_INVALID);

            })
            zlib.compressFile(path1, outFile, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
            }, (err, data) => {
I
inter515 已提交
1317
                console.info("compressFile result");
I
inter515 已提交
1318 1319 1320
                expect(err.code).assertEqual(OUTPUT_FILE_INVALID);
                done();
            })
I
inter515 已提交
1321
            console.info("==================compressFileOutFileNull end==================");
I
inter515 已提交
1322 1323 1324
        })


I
inter515 已提交
1325 1326 1327 1328
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0081
        * @tc.name: compressFileOutFileNull
        * @tc.desc: test compressFile when outFile is null
I
add xts  
inter515 已提交
1329
        */
I
inter515 已提交
1330
        it('compressFileOutFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1331
            console.info("==================compressFileOutFileNull start==================");
I
inter515 已提交
1332 1333 1334 1335 1336 1337 1338 1339
            let path1 = dir + "/compressFileOutFileNull.txt";
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("fileio write data to file successfully :" + number);
            }).catch(function (err) {
                console.info("fileio write data to file failed with error:" + err);
                expect(err).assertFail();
            });
I
inter515 已提交
1340
            try {
I
inter515 已提交
1341 1342 1343
                await zlib.compressFile(path1, null, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }).then((data) => {
I
inter515 已提交
1344
                    console.info("compressFileOutFileNull invalid src file success!");
I
inter515 已提交
1345 1346
                    expect().assertFail();
                }).catch((err) => {
I
inter515 已提交
1347
                    console.info("compressFileOutFileNull zipFile fail: " + JSON.stringify(err));
I
inter515 已提交
1348 1349
                    expect().assertFail();
                })
I
inter515 已提交
1350
            } catch (err) {
I
inter515 已提交
1351 1352
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1353
            try {
I
inter515 已提交
1354 1355 1356
                zlib.compressFile(path1, null, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }, (err, data) => {
I
inter515 已提交
1357
                    console.info("compressFile result");
I
inter515 已提交
1358 1359 1360
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1361
            } catch (err) {
I
inter515 已提交
1362 1363 1364
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
I
inter515 已提交
1365
            console.info("==================compressFileOutFileNull end==================");
I
inter515 已提交
1366 1367 1368 1369 1370 1371 1372
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0082
        * @tc.name: compressFileOptionNull
        * @tc.desc: test compressFile when option is null
        */
I
inter515 已提交
1373
        it('compressFileOptionNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1374
            console.info("==================compressFileOptionNull start==================");
I
inter515 已提交
1375 1376 1377 1378 1379 1380 1381 1382 1383
            let path1 = dir + "/compressFileOptionNull.txt";
            let zipDest1 = dir + "/compressFileOptionNull.zip";
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("fileio write data to file successfully :" + number);
            }).catch(function (err) {
                console.info("fileio write data to file failed with error:" + err);
                expect(err).assertFail();
            });
I
inter515 已提交
1384
            try {
I
inter515 已提交
1385
                await zlib.compressFile(path1, zipDest1, null).then((data) => {
I
inter515 已提交
1386
                    console.info("compressFileOptionNull invalid src file success!");
I
inter515 已提交
1387 1388
                    expect().assertFail();
                }).catch((err) => {
I
inter515 已提交
1389
                    console.info("compressFileOptionNull zipFile fail: " + JSON.stringify(err));
I
inter515 已提交
1390 1391
                    expect().assertFail();
                })
I
inter515 已提交
1392
            } catch (err) {
I
inter515 已提交
1393 1394
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1395
            try {
I
inter515 已提交
1396
                zlib.compressFile(path1, zipDest1, null, (err, data) => {
I
inter515 已提交
1397
                    console.info("compressFile result");
I
inter515 已提交
1398 1399 1400
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1401
            } catch (err) {
I
inter515 已提交
1402 1403 1404
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
I
inter515 已提交
1405
            console.info("==================compressFileOptionNull end==================");
I
inter515 已提交
1406 1407
        })

I
inter515 已提交
1408 1409 1410 1411 1412 1413
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0083
        * @tc.name: compressFileInvalidOption
        * @tc.desc: test compressFile when option is invalid
        */
        it('compressFileInvalidOption', Level.LEVEL3, async function (done) {
I
inter515 已提交
1414
            console.info("==================compressFileInvalidOption start==================");
I
inter515 已提交
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
            let path1 = dir + "/compressFileInvalidOption.txt";
            let zipDest1 = dir + "/compressFileInvalidOption.zip";
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("fileio write data to file successfully :" + number);
            }).catch(function (err) {
                console.info("fileio write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path1, zipDest1, {
                memLevel: -1
            }).then((data) => {
I
inter515 已提交
1427
                console.info("compressFileInvalidOption invalid src file success!");
I
inter515 已提交
1428 1429
                expect(data).assertNull();
            }).catch((err) => {
I
inter515 已提交
1430
                console.info("compressFileInvalidOption zipFile fail: " + JSON.stringify(err));
I
inter515 已提交
1431 1432 1433 1434 1435
                expect().assertFail();
            })
            zlib.compressFile(path1, zipDest1, {
                memLevel: -1
            }, (err, data) => {
I
inter515 已提交
1436
                console.info("compressFile result");
I
inter515 已提交
1437 1438 1439 1440
                expect(data).assertUndefined();
                expect(err).assertNull();
                done();
            })
I
inter515 已提交
1441
            console.info("==================compressFileInvalidOption end==================");
I
inter515 已提交
1442 1443
        })

I
inter515 已提交
1444 1445 1446 1447 1448
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0084
        * @tc.name: compressFileStrategyNull
        * @tc.desc: test compressFile when strategy is null
        */
I
inter515 已提交
1449
        it('compressFileStrategyNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1450
            console.info("==================compressFileStrategyNull start==================");
I
inter515 已提交
1451 1452 1453 1454 1455 1456 1457 1458 1459
            let path1 = dir + "/compressFileStrategyNull.txt";
            let zipDest1 = dir + "/compressFileStrategyNull.zip";
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("fileio write data to file successfully :" + number);
            }).catch(function (err) {
                console.info("fileio write data to file failed with error:" + err);
                expect(err).assertFail();
            });
I
inter515 已提交
1460
            try {
I
inter515 已提交
1461 1462 1463
                await zlib.compressFile(path1, zipDest1, {
                    strategy: null
                }).then((data) => {
I
inter515 已提交
1464
                    console.info("compressFileStrategyNull invalid src file success!");
I
inter515 已提交
1465
                }).catch((err) => {
I
inter515 已提交
1466
                    console.info("compressFileStrategyNull zipFile fail: " + JSON.stringify(err));
I
inter515 已提交
1467 1468
                    expect().assertFail();
                })
I
inter515 已提交
1469
            } catch (err) {
W
wangtiantian 已提交
1470
                expect().assertFail();
I
inter515 已提交
1471
            }
I
inter515 已提交
1472
            try {
I
inter515 已提交
1473 1474 1475
                zlib.compressFile(path1, zipDest1, {
                    strategy: null
                }, (err, data) => {
I
inter515 已提交
1476
                    console.info("compressFile result");
I
inter515 已提交
1477 1478
                    done();
                })
I
inter515 已提交
1479
            } catch (err) {
W
wangtiantian 已提交
1480
                expect().assertFail();
I
inter515 已提交
1481 1482
                done();
            }
I
inter515 已提交
1483
            console.info("==================compressFileOutFileNull end==================");
I
inter515 已提交
1484 1485 1486
        })

        /*
I
inter515 已提交
1487
        * @tc.number: SUB_BMS_TOOL_ZLIB_0086
I
inter515 已提交
1488 1489 1490
        * @tc.name: decompressFileTest
        * @tc.desc: test decompressFile when inFile and out file is valid
        */
I
inter515 已提交
1491
        it('decompressFileTest', Level.LEVEL2, async function (done) {
I
inter515 已提交
1492
            console.info("==================decompressFileTestOutDir start==================");
I
inter515 已提交
1493 1494 1495 1496 1497 1498 1499
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/decompressFileTest1.zip";
            let zipDest2 = dir + "/decompressFileTest2.zip";
            let unzipdir1 = dir + "/decompressFileTest1";
            let unzipdir2 = dir + "/decompressFileTest2";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
I
add xts  
inter515 已提交
1500 1501
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
I
inter515 已提交
1502
                console.info("decompressFileTest write data to file success " + JSON.stringify(number));
I
add xts  
inter515 已提交
1503
            }).catch(function (err) {
I
inter515 已提交
1504
                console.info("decompressFileTest write data to file failed with error:" + err);
I
add xts  
inter515 已提交
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("compressFile success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("compressFile fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("compressFile success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("compressFile fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
I
inter515 已提交
1538
                console.info("decompressFileTest mkdir successfully");
I
add xts  
inter515 已提交
1539
            }).catch(function (error) {
I
inter515 已提交
1540
                console.info("decompressFileTest mkdir failed with error:" + error);
I
add xts  
inter515 已提交
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFile success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFile fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
I
inter515 已提交
1556
                console.info("decompressFileTest mkdir successfully");
I
add xts  
inter515 已提交
1557
            }).catch(function (error) {
I
inter515 已提交
1558
                console.info("decompressFileTest mkdir failed with error:" + error);
I
add xts  
inter515 已提交
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("decompressFile success2 " + JSON.stringify(data));
                console.info("decompressFile success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })
1574

I
inter515 已提交
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0087
        * @tc.name: decompressDifferentLevel
        * @tc.desc: test decompressFile when inFile and out file is valid
        */
        it('decompressDifferentLevel', Level.LEVEL2, async function (done) {
            console.info("==================decompressDifferentLevel start==================");
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/decompressFileTest1.zip";
            let zipDest2 = dir + "/decompressFileTest2.zip";
            let unzipdir1 = dir + "/SUB_BMS_TOOL_ZLIB_0087a";
            let unzipdir2 = dir + "/SUB_BMS_TOOL_ZLIB_0087b";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressDifferentLevel write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressDifferentLevel write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_BEST_COMPRESSION
            }).then(data => {
                console.info("decompressDifferentLevel success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressDifferentLevel fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED
            }).then(data => {
                console.info("decompressDifferentLevel success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressDifferentLevel  fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
                console.info("decompressDifferentLevel mkdir successfully");
            }).catch(function (error) {
                console.info("decompressDifferentLevel mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_BEST_COMPRESSION
            }).then(data => {
                console.info("decompressDifferentLevel success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressDifferentLevel fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
                console.info("decompressDifferentLevel mkdir successfully");
            }).catch(function (error) {
                console.info("decompressDifferentLevel mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED
            }, (err, data) => {
                console.info("decompressDifferentLevel success2 " + JSON.stringify(data));
                console.info("decompressDifferentLevel success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })

I
add xts  
inter515 已提交
1664
        /*
I
inter515 已提交
1665 1666 1667
        * @tc.number: SUB_BMS_TOOL_ZLIB_0088
        * @tc.name: decompressFileInFileNotExist
        * @tc.desc: test decompressFile when inFile is not exist
I
add xts  
inter515 已提交
1668
        */
I
inter515 已提交
1669
        it('decompressFileInFileNotExist', Level.LEVEL3, async function (done) {
I
inter515 已提交
1670
            console.info("==================decompressFileInFileNotExist start==================");
I
inter515 已提交
1671 1672
            let zipDest = dir + "/noneexist.zip";
            let unzipdir = dir + "/decompressFileInFileNotExist";
I
add xts  
inter515 已提交
1673
            await fileio.mkdir(unzipdir).then(function () {
I
inter515 已提交
1674
                console.info("fileio mkdir successfully");
I
add xts  
inter515 已提交
1675
            }).catch(function (error) {
I
inter515 已提交
1676
                console.info("fileio mkdir failed with error:" + error);
I
add xts  
inter515 已提交
1677 1678 1679 1680 1681
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest, unzipdir, {
                strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
            }).then(data => {
I
inter515 已提交
1682
                console.info("decompressFile data: " + data);
I
add xts  
inter515 已提交
1683 1684 1685
                expect(data).assertFail(null);
                done();
            }).catch(err => {
I
inter515 已提交
1686
                console.info("decompress fail: " + JSON.stringify(err));
I
add xts  
inter515 已提交
1687 1688 1689
                expect(err.code).assertEqual(SRC_FILE_INVALID);
                done();
            })
I
inter515 已提交
1690 1691 1692 1693 1694 1695 1696
            zlib.decompressFile(zipDest, unzipdir, {
                strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
            }, (err, data) => {
                expect(err.code).assertEqual(SRC_FILE_INVALID);
                expect(data).assertEqual(undefined);
                done();
            })
I
inter515 已提交
1697
            console.info("==================decompressFileInFileNotExist end==================");
I
inter515 已提交
1698 1699 1700 1701 1702 1703 1704
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0089
        * @tc.name: decompressFileInFileNull
        * @tc.desc: test decompressFile when inFile is null
        */
I
inter515 已提交
1705
        it('decompressFileInFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1706
            console.info("==================decompressFileInFileNull start==================");
I
inter515 已提交
1707 1708 1709 1710 1711 1712 1713
            let unzipdir = dir + "/decompressFileInFileNull";
            await fileio.mkdir(unzipdir).then(function () {
                console.info("fileio mkdir successfully");
            }).catch(function (error) {
                console.info("fileio mkdir failed with error:" + error);
                expect(error).assertFail();
            });
I
inter515 已提交
1714
            try {
I
inter515 已提交
1715 1716 1717
                await zlib.decompressFile(null, unzipdir, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }).then(data => {
I
inter515 已提交
1718
                    console.info("decompressFile data: " + data);
I
inter515 已提交
1719 1720
                    expect().assertFail();
                }).catch(err => {
I
inter515 已提交
1721
                    console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1722 1723
                    expect().assertFail();
                })
I
inter515 已提交
1724
            } catch (err) {
I
inter515 已提交
1725
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1726 1727
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1728
            try {
I
inter515 已提交
1729 1730 1731 1732 1733 1734
                zlib.decompressFile(null, unzipdir, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }, (err, data) => {
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1735
            } catch (err) {
I
inter515 已提交
1736
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1737 1738 1739
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
I
inter515 已提交
1740
            console.info("==================decompressFileInFileNull end==================");
I
inter515 已提交
1741 1742
        })

I
inter515 已提交
1743 1744 1745 1746 1747 1748
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0090
        * @tc.name: decompressFileOutFileNotExist
        * @tc.desc: test decompressFile when outFile is not existed.
        */
        it('decompressFileOutFileNotExist', Level.LEVEL3, async function (done) {
I
inter515 已提交
1749
            console.info("==================decompressFileOutFileNotExist start==================");
I
inter515 已提交
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
            let path = dir + "/decompressFileOutFileNotExist.txt";
            let zipDest1 = dir + "/decompressFileOutFileNotExist.zip";
            let outFile = "/111111/22222/test";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileOutFileNotExist write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileOutFileNotExist write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("compressFile success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("compressFile fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.decompressFile(zipDest1, outFile, {
                strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
            }).then(data => {
I
inter515 已提交
1778
                console.info("decompressFile data: " + data);
I
inter515 已提交
1779 1780
                expect().assertFail();
            }).catch(err => {
I
inter515 已提交
1781
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1782 1783 1784 1785 1786 1787 1788 1789
                expect(err.code).assertEqual(OUTPUT_FILE_INVALID);
            })
            zlib.decompressFile(zipDest1, outFile, {
                strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
            }, (err, data) => {
                expect(err.code).assertEqual(OUTPUT_FILE_INVALID);
                done();
            })
I
inter515 已提交
1790
            console.info("==================decompressFileOutFileNotExist end==================");
I
inter515 已提交
1791 1792
        })

I
inter515 已提交
1793 1794 1795 1796 1797
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0091
        * @tc.name: decompressFileOutFileNull
        * @tc.desc: test decompressFile when outFile is null
        */
I
inter515 已提交
1798
        it('decompressFileOutFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1799
            console.info("==================decompressFileOutFileNull start==================");
I
inter515 已提交
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
            let path = dir + "/decompressFileOutFileNull.txt";
            let zipDest1 = dir + "/decompressFileOutFileNull.zip";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileOutFileNull write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileOutFileNull write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("compressFile success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("compressFile fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
I
inter515 已提交
1824
            try {
I
inter515 已提交
1825 1826 1827
                await zlib.decompressFile(zipDest1, null, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }).then(data => {
I
inter515 已提交
1828
                    console.info("decompressFile data: " + data);
I
inter515 已提交
1829 1830
                    expect().assertFail();
                }).catch(err => {
I
inter515 已提交
1831
                    console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1832 1833
                    expect().assertFail();
                })
I
inter515 已提交
1834
            } catch (err) {
I
inter515 已提交
1835
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1836 1837
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1838
            try {
I
inter515 已提交
1839 1840 1841 1842 1843 1844
                zlib.decompressFile(zipDest1, null, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }, (err, data) => {
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1845
            } catch (err) {
I
inter515 已提交
1846
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1847 1848 1849
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
I
inter515 已提交
1850
            console.info("==================decompressFileOutFileNull end==================");
I
inter515 已提交
1851 1852 1853 1854 1855 1856 1857
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0092
        * @tc.name: decompressFileOptionNull
        * @tc.desc: test decompressFile when option is null
        */
I
inter515 已提交
1858
        it('decompressFileOptionNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1859
            console.info("==================decompressFileOptionNull start==================");
I
inter515 已提交
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890
            let path = dir + "/decompressFileOptionNull.txt";
            let zipDest1 = dir + "/decompressFileOptionNull.zip";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("SUB_BMS_TOOL_ZLIB_0087 write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("SUB_BMS_TOOL_ZLIB_0087 write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("compressFile success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("compressFile fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            let unzipdir = dir + "/decompressFileOptionNull";
            await fileio.mkdir(unzipdir).then(function () {
                console.info("fileio mkdir successfully");
            }).catch(function (error) {
                console.info("fileio mkdir failed with error:" + error);
                expect(error).assertFail();
            });
I
inter515 已提交
1891
            try {
I
inter515 已提交
1892
                await zlib.decompressFile(zipDest1, unzipdir, null).then(data => {
I
inter515 已提交
1893
                    console.info("decompressFile data: " + data);
I
inter515 已提交
1894 1895
                    expect().assertFail();
                }).catch(err => {
I
inter515 已提交
1896
                    console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1897 1898
                    expect().assertFail();
                })
I
inter515 已提交
1899
            } catch (err) {
I
inter515 已提交
1900
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1901 1902
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1903
            try {
I
inter515 已提交
1904 1905 1906 1907
                zlib.decompressFile(zipDest1, unzipdir, null, (err, data) => {
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1908
            } catch (err) {
I
inter515 已提交
1909
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1910 1911 1912
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
I
inter515 已提交
1913
            console.info("==================decompressFileOutFileNull end==================");
1914 1915
        })

I
inter515 已提交
1916 1917 1918 1919 1920 1921
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0093
        * @tc.name: decompressFileInvalidOption
        * @tc.desc: test decompressFile when option is invalid
        */
        it('decompressFileInvalidOption', Level.LEVEL3, async function (done) {
I
inter515 已提交
1922
            console.info("==================decompressFileInvalidOption start==================");
I
inter515 已提交
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
            let path = dir + "/decompressFileInvalidOption.txt";
            let zipDest1 = dir + "/decompressFileInvalidOption.zip";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("SUB_BMS_TOOL_ZLIB_0087 write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("SUB_BMS_TOOL_ZLIB_0087 write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("compressFile success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("compressFile fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            let unzipdir = dir + "/decompressFileInvalidOption";
            await fileio.mkdir(unzipdir).then(function () {
                console.info("fileio mkdir successfully");
            }).catch(function (error) {
                console.info("fileio mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir, {
                memLevel: -1
            }).then(data => {
I
inter515 已提交
1957
                console.info("decompressFile data: " + data);
I
inter515 已提交
1958 1959
                expect(data).assertNull();
            }).catch(err => {
I
inter515 已提交
1960
                console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
1961 1962 1963 1964 1965 1966 1967 1968 1969
                expect().assertFail();
            })
            zlib.decompressFile(zipDest1, unzipdir, {
                memLevel: -1
            }, (err, data) => {
                expect(data).assertUndefined();
                expect(err).assertNull();
                done();
            })
I
inter515 已提交
1970
            console.info("==================decompressFileOutFileNull end==================");
I
inter515 已提交
1971 1972
        })

I
inter515 已提交
1973 1974 1975 1976 1977
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0094
        * @tc.name: decompressFileStrategyNull
        * @tc.desc: test decompressFile when strategy is null
        */
I
inter515 已提交
1978
        it('decompressFileStrategyNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1979
            console.info("==================decompressFileStrategyNull start==================");
I
inter515 已提交
1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
            let path = dir + "/decompressFileStrategyNull.txt";
            let zipDest1 = dir + "/decompressFileStrategyNull.zip";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileStrategyNull write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileStrategyNull write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("compressFile success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("compressFile fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            let unzipdir = dir + "/decompressFileStrategyNull";
            await fileio.mkdir(unzipdir).then(function () {
                console.info("fileio mkdir successfully");
            }).catch(function (error) {
                console.info("fileio mkdir failed with error:" + error);
                expect(error).assertFail();
            });
I
inter515 已提交
2011
            try {
I
inter515 已提交
2012 2013 2014
                await zlib.decompressFile(zipDest1, unzipdir, {
                    strategy: null
                }).then(data => {
I
inter515 已提交
2015
                    console.info("decompressFile data: " + data);
I
inter515 已提交
2016
                }).catch(err => {
I
inter515 已提交
2017
                    console.info("decompress fail: " + JSON.stringify(err));
I
inter515 已提交
2018 2019
                    expect().assertFail();
                })
I
inter515 已提交
2020
            } catch (err) {
I
inter515 已提交
2021
                console.info("decompress fail: " + JSON.stringify(err));
W
wangtiantian 已提交
2022
                expect().assertFail();
I
inter515 已提交
2023
            }
I
inter515 已提交
2024
            try {
I
inter515 已提交
2025 2026 2027
                zlib.decompressFile(zipDest1, unzipdir, {
                    strategy: null
                }, (err, data) => {
I
inter515 已提交
2028
                    console.info("decompressFile data: " + data);
I
inter515 已提交
2029 2030
                    done();
                })
I
inter515 已提交
2031
            } catch (err) {
I
inter515 已提交
2032
                console.info("decompress fail: " + JSON.stringify(err));
W
wangtiantian 已提交
2033
                expect().assertFail();
I
inter515 已提交
2034 2035
                done();
            }
I
inter515 已提交
2036
            console.info("==================decompressFileStrategyNull end==================");
I
inter515 已提交
2037
        })
I
inter515 已提交
2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0096
        * @tc.name: decompressFileInfileSpecialCharacters
        * @tc.desc: test decompressFile when outFile is a dir
        */
        it('decompressFileInfileSpecialCharacters', Level.LEVEL2, async function (done) {
            console.info("==================decompressFileInfileSpecialCharacters start==================");
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/@#@##.zip";
            let zipDest2 = dir + "/@#@#@.zip";
            let unzipdir1 = dir + "/SUB_BMS_TOOL_ZLIB_0096a";
            let unzipdir2 = dir + "/SUB_BMS_TOOL_ZLIB_0096b";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileInfileSpecialCharacters write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileInfileSpecialCharacters write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileSpecialCharacters success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileSpecialCharacters fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileSpecialCharacters success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileSpecialCharacters fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
                console.info("decompressFileInfileSpecialCharacters mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileSpecialCharacters mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileSpecialCharacters success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileSpecialCharacters fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
                console.info("decompressFileInfileSpecialCharacters mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileSpecialCharacters mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("decompressFileInfileSpecialCharacters success2 " + JSON.stringify(data));
                console.info("decompressFileInfileSpecialCharacters success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })

I
inter515 已提交
2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0097
        * @tc.name: decompressFileOutfileSpecialCharDir
        * @tc.desc: test decompressFile when outFile is a dir
        */
        it('decompressFileOutfileSpecialCharDir', Level.LEVEL2, async function (done) {
            console.info("==================decompressFileOutfileSpecialCharDir start==================");
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/@#@##.zip";
            let zipDest2 = dir + "/@#@#@.zip";
            let unzipdir1 = dir + "/@####1";
            let unzipdir2 = dir + "/#@@@@2";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileOutfileSpecialCharDir write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileOutfileSpecialCharDir write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileOutfileSpecialCharDir success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileOutfileSpecialCharDir fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileOutfileSpecialCharDir success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileOutfileSpecialCharDir fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
                console.info("decompressFileOutfileSpecialCharDir mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileOutfileSpecialCharDir mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileOutfileSpecialCharDir success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileOutfileSpecialCharDir fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
                console.info("decompressFileOutfileSpecialCharDir mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileOutfileSpecialCharDir mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("decompressFileOutfileSpecialCharDir success2 " + JSON.stringify(data));
                console.info("decompressFileOutfileSpecialCharDir success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0098
        * @tc.name: decompressFileInfileChineseDir
        * @tc.desc: test decompressFile when outFile is a dir
        */
        it('decompressFileInfileChineseDir', Level.LEVEL2, async function (done) {
            console.info("==================decompressFileInfileChineseDir start==================");
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/解压1.zip";
            let zipDest2 = dir + "/解压2.zip";
            let unzipdir1 = dir + "/文件夹1";
            let unzipdir2 = dir + "/文件夹2";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileInfileChineseDir write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileInfileChineseDir write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileChineseDir success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileChineseDir fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileChineseDir success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileChineseDir fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
                console.info("decompressFileInfileChineseDir mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileChineseDir mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileChineseDir success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileChineseDir fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
                console.info("decompressFileInfileChineseDir mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileChineseDir mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("decompressFileInfileChineseDir success2 " + JSON.stringify(data));
                console.info("decompressFileInfileChineseDir success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })

I
inter515 已提交
2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0099
        * @tc.name: decompressFileInfileChinesePath
        * @tc.desc: test decompressFile when outFile is a dir
        */
        it('decompressFileInfileChinesePath', Level.LEVEL2, async function (done) {
            console.info("==================decompressFileInfileChinesePath start==================");
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/解压1.zip";
            let zipDest2 = dir + "/解压2.zip";
            let unzipdir1 = dir + "/SUB_BMS_TOOL_ZLIB_0099a";
            let unzipdir2 = dir + "/SUB_BMS_TOOL_ZLIB_0099b";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileInfileChinesePath write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileInfileChinesePath write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileChinesePath success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileChinesePath fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileChinesePath success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileChinesePath fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
                console.info("decompressFileInfileChinesePath mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileChinesePath mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileChinesePath success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileChinesePath fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
                console.info("decompressFileInfileChinesePath mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileChinesePath mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("decompressFileInfileChinesePath success2 " + JSON.stringify(data));
                console.info("decompressFileInfileChinesePath success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0100
        * @tc.name: decompressFileInfileZipPath
        * @tc.desc: test decompressFile when outFile is a dir
        */
        it('decompressFileInfileZipPath', Level.LEVEL2, async function (done) {
            console.info("==================decompressFileInfileZipPath start==================");
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/1#@.zip.zip";
            let zipDest2 = dir + "/2##.zip.zip";
            let unzipdir1 = dir + "/SUB_BMS_TOOL_ZLIB_0100a";
            let unzipdir2 = dir + "/SUB_BMS_TOOL_ZLIB_0100b";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileInfileZipPath write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileInfileZipPath write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileZipPath success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileZipPath fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileZipPath success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileZipPath fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
                console.info("decompressFileInfileZipPath mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileZipPath mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileZipPath success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileZipPath fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
                console.info("decompressFileInfileZipPath mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileZipPath mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("decompressFileInfileZipPath success2 " + JSON.stringify(data));
                console.info("decompressFileInfileZipPath success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0101
        * @tc.name: decompressFileInfileBlankPath
        * @tc.desc: test decompressFile when outFile is a dir
        */
        it('decompressFileInfileBlankPath', Level.LEVEL2, async function (done) {
            console.info("==================decompressFileInfileBlankPath start==================");
            let path = dir + "/decompressFileTest.txt";
            let zipDest1 = dir + "/解压 1#@.zip";
            let zipDest2 = dir + "/解压 2##.zip";
            let unzipdir1 = dir + "/SUB_BMS_TOOL_ZLIB_0101a";
            let unzipdir2 = dir + "/SUB_BMS_TOOL_ZLIB_0101b";
            let finalFile1 = unzipdir1 + "/decompressFileTest.txt";
            let finalFile2 = unzipdir2 + "/decompressFileTest.txt";
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
                console.info("decompressFileInfileBlankPath write data to file success " + JSON.stringify(number));
            }).catch(function (err) {
                console.info("decompressFileInfileBlankPath write data to file failed with error:" + err);
                expect(err).assertFail();
            });
            await zlib.compressFile(path, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileBlankPath success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileBlankPath fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await zlib.compressFile(path, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileBlankPath success " + JSON.stringify(data));
                let zipStat = fileio.statSync(zipDest2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                let srcSize = fileio.statSync(path).size;
                let destSize = zipStat.size;
                expect(srcSize > destSize).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileBlankPath fail " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir1).then(function () {
                console.info("decompressFileInfileBlankPath mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileBlankPath mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest1, unzipdir1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then(data => {
                console.info("decompressFileInfileBlankPath success1 " + JSON.stringify(data));
                let zipStat = fileio.statSync(finalFile1);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(null);
            }).catch(err => {
                console.info("decompressFileInfileBlankPath fail1 " + JSON.stringify(err));
                expect(err).assertFail();
            })
            await fileio.mkdir(unzipdir2).then(function () {
                console.info("decompressFileInfileBlankPath mkdir successfully");
            }).catch(function (error) {
                console.info("decompressFileInfileBlankPath mkdir failed with error:" + error);
                expect(error).assertFail();
            });
            zlib.decompressFile(zipDest2, unzipdir2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
                console.info("decompressFileInfileBlankPath success2 " + JSON.stringify(data));
                console.info("decompressFileInfileBlankPath success2 " + JSON.stringify(err));
                let zipStat = fileio.statSync(finalFile2);
                let isFile = zipStat.isFile();
                expect(isFile).assertTrue();
                expect(data).assertEqual(undefined);
                expect(err).assertEqual(null);
                done();
            })
        })


2574
    })
J
jiyong_sd 已提交
2575
}
K
kirl75 已提交
2576