actszipfileandunzipfiletest.test.js 83.9 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 24
let dir = "";
let infos = "";
let SRC_FILE_INVALID = 900001;
let PARAM_ERROR = 401;
I
add xts  
inter515 已提交
25

J
jiyong_sd 已提交
26
export default function ActsZlibTest() {
I
add xts  
inter515 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39
    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 已提交
40

I
add xts  
inter515 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        /*
        * @tc.number: ACTS_ZipFile_0100
        * @tc.name: zipFile
        * @tc.desc: inFile is empty
        */
        it('ACTS_ZipFile_0100', 0, async function (done) {
            console.log("==================ACTS_ZipFile_0100 start==================");
            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) => {
                console.log("ACTS_ZipFile_0100 data: " + data);
                expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                done();
            }).catch((err) => {
                console.log("ACTS_ZipFile_0100 zipFile fail: " + err);
                expect(err).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                done();
            })
            console.log("==================ACTS_ZipFile_0100 end==================");
        })
K
kirl75 已提交
63

I
add xts  
inter515 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        /*
        * @tc.number: ACTS_ZipFile_0200
        * @tc.name: zipFile
        * @tc.desc: inFile doesn't exist
        */
        it('ACTS_ZipFile_0200', 0, async function (done) {
            console.log("==================ACTS_ZipFile_0200 start==================");
            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) => {
                    console.log("ACTS_ZipFile_0200 data: " + data);
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
                    console.log("ACTS_ZipFile_0200 zipFile fail: " + err);
                    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();
            });
            console.log("==================ACTS_ZipFile_0200 end==================");
        })
K
kirl75 已提交
94

I
add xts  
inter515 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        /*
        * @tc.number: ACTS_ZipFile_0300
        * @tc.name: zipFile
        * @tc.desc: output file not specified
        */
        it('ACTS_ZipFile_0300', 0, async function (done) {
            console.log("==================ACTS_ZipFile_0300 start==================");
            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) => {
                    console.log("ACTS_ZipFile_0300 data: " + data);
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
                    console.log("ACTS_ZipFile_0300 zipFile fail: " + err);
                    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();
            });
            console.log("==================ACTS_ZipFile_0300 end==================");
        })
K
kirl75 已提交
125

I
add xts  
inter515 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        /*
        * @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) {
            console.log("==================ACTS_ZipFile_0400 start==================");
            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) => {
                    console.log("ACTS_ZipFile_0400 data: " + data);
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
                    console.log("ACTS_ZipFile_0400 zipFile fail: " + err);
                    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();
            });
            console.log("==================ACTS_ZipFile_0400 end==================");
        })
K
kirl75 已提交
156

I
add xts  
inter515 已提交
157 158 159 160 161 162 163 164 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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
        /*
        * @tc.number: ACTS_ZipFile_2200
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_NO_COMPRESSION,
        */
        it('ACTS_ZipFile_2200', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2200 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2200 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2200 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2200 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2200 end==================");
R
renyi 已提交
215
        });
K
kirl75 已提交
216

I
add xts  
inter515 已提交
217 218 219 220 221 222 223 224 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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        /*
        * @tc.number: ACTS_ZipFile_2300
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_BEST_SPEED,
        */
        it('ACTS_ZipFile_2300', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2300 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2300 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2300 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2300 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2300 end==================");
        })
K
kirl75 已提交
276

I
add xts  
inter515 已提交
277 278 279 280 281 282 283 284 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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
        /*
        * @tc.number: ACTS_ZipFile_2400
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_BEST_COMPRESSION,
        */
        it('ACTS_ZipFile_2400', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2400 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2400 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2400 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2400 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2400 end==================");
R
renyi 已提交
335
        });
K
kirl75 已提交
336

I
add xts  
inter515 已提交
337 338 339 340 341 342 343 344 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 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
        /*
        * @tc.number: ACTS_ZipFile_2500
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_LEVEL_DEFAULT_COMPRESSION,
        */
        it('ACTS_ZipFile_2500', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2500 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2500 err: " + err);
                            expect(err).assertFail();
                            done()
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2500 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2500 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2500 end==================");
R
renyi 已提交
395
        });
K
kirl75 已提交
396

I
add xts  
inter515 已提交
397 398 399 400 401 402 403 404 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 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
        /*
        * @tc.number: ACTS_ZipFile_2600
        * @tc.name: zipFile
        * @tc.desc: MEM_LEVEL_MIN_MEMLEVEL,,
        */
        it('ACTS_ZipFile_2600', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2600 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2600 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2600 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2600 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2600 end==================");
R
renyi 已提交
455
        });
K
kirl75 已提交
456

I
add xts  
inter515 已提交
457 458 459 460 461 462 463 464 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 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
        /*
        * @tc.number: ACTS_ZipFile_2700
        * @tc.name: zipFile
        * @tc.desc: MEM_LEVEL_MAX_MEMLEVEL,,
        */
        it('ACTS_ZipFile_2700', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2700 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2700 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2700 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2700 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2700 end==================");
R
renyi 已提交
515
        });
K
kirl75 已提交
516

I
add xts  
inter515 已提交
517 518 519 520 521 522 523 524 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 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
        /*
        * @tc.number: ACTS_ZipFile_2800
        * @tc.name: zipFile
        * @tc.desc: MEM_LEVEL_DEFAULT_MEMLEVEL,,
        */
        it('ACTS_ZipFile_2800', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2800 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2800 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2800 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2800 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2800 end==================");
R
renyi 已提交
575
        });
K
kirl75 已提交
576

I
add xts  
inter515 已提交
577 578 579 580 581 582 583 584 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 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
        /*
        * @tc.number: ACTS_ZipFile_2900
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_DEFAULT_STRATEGY,,
        */
        it('ACTS_ZipFile_2900', 0, async function (done) {
            console.log("==================ACTS_ZipFile_2900 start==================");
            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) => {
                            console.log("ACTS_ZipFile_2900 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_2900 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_2900 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_2900 end==================");
        });
K
kirl75 已提交
636

I
add xts  
inter515 已提交
637 638 639 640 641 642 643 644 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 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
        /*
        * @tc.number: ACTS_ZipFile_3000
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FILTERED,,
        */
        it('ACTS_ZipFile_3000', 0, async function (done) {
            console.log("==================ACTS_ZipFile_3000 start==================");
            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) => {
                            console.log("ACTS_ZipFile_3000 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3000 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3000 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_3000 end==================");
R
renyi 已提交
695
        });
K
kirl75 已提交
696

I
add xts  
inter515 已提交
697 698 699 700 701 702 703 704 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 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
        /*
        * @tc.number: ACTS_ZipFile_3100
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_HUFFMAN_ONLY,,
        */
        it('ACTS_ZipFile_3100', 0, async function (done) {
            console.log("==================ACTS_ZipFile_3100 start==================");
            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) => {
                            console.log("ACTS_ZipFile_3100 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3100 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3100 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_3100 end==================");
R
renyi 已提交
755
        });
K
kirl75 已提交
756

I
add xts  
inter515 已提交
757 758 759 760 761 762 763 764 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 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
        /*
        * @tc.number: ACTS_ZipFile_3200
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_RLE,,
        */
        it('ACTS_ZipFile_3200', 0, async function (done) {
            console.log("==================ACTS_ZipFile_3200 start==================");
            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) => {
                            console.log("ACTS_ZipFile_3200 err: " + err);
                            done();
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3200 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3200 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_3200 end==================");
R
renyi 已提交
816
        });
K
kirl75 已提交
817

I
add xts  
inter515 已提交
818 819 820 821 822 823 824 825 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 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
        /*
        * @tc.number: ACTS_ZipFile_3300
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FIXED,,
        */
        it('ACTS_ZipFile_3300', 0, async function (done) {
            console.log("==================ACTS_ZipFile_3300 start==================");
            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) => {
                            console.log("ACTS_ZipFile_3300 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_3300 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch((err) => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_3300 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_3300 end==================");
R
renyi 已提交
876
        });
K
kirl75 已提交
877

I
add xts  
inter515 已提交
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
        /*
        * @tc.number: ACTS_ZipFile_3500
        * @tc.name: zipFile
        * @tc.desc: INPUT_FILE_NOT_EXIST,,
        */
        it('ACTS_ZipFile_3500', 0, async function (done) {
            console.log("==================ACTS_ZipFile_3500 start==================");
            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) => {
                    console.log("ACTS_ZipFile_3500 data: " + data);
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
                    console.log("ACTS_ZipFile_3500 err: " + err);
                    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();
            });
            console.log("==================ACTS_ZipFile_3500 end ==================");
        })
K
kirl75 已提交
909

I
add xts  
inter515 已提交
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
        /*
        * @tc.number: ACTS_ZipFile_3600
        * @tc.name: zipFile
        * @tc.desc: INPUT_FILE_NULL,,
        */
        it('ACTS_ZipFile_3600', 0, async function (done) {
            console.log("==================ACTS_ZipFile_3600 start==================");
            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) => {
                    console.log("ACTS_ZipFile_3600 data: " + data);
                    expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                    done();
                }).catch((err) => {
                    console.log("ACTS_ZipFile_3600 err: " + err);
                    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();
            });
            console.log("==================ACTS_ZipFile_3600 end ==================")
        })
K
kirl75 已提交
940

I
add xts  
inter515 已提交
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
        /*
        * @tc.number: ACTS_ZipFile_4500
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FILTERED_CALLBACK,,
        */
        it('ACTS_ZipFile_4500', 0, async function (done) {
            console.log("==================ACTS_ZipFile_4500 start==================");
            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) => {
                            console.log("ACTS_ZipFile_4500 data: " + data);
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
                            done();
                        }).catch((err) => {
                            console.log("ACTS_ZipFile_4500 err: " + err);
                            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) => {
                    console.log("ACTS_ZipFile_4500 zipFile fail: " + err);
                    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();
            });
            console.log("==================ACTS_ZipFile_4500 end==================");
        })

        /*
        * @tc.number: ACTS_ZipFile_4900
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FILTERED_PROMISE,
        */
        it('ACTS_ZipFile_4900', 0, async function (done) {
            console.log("==================ACTS_ZipFile_4900 start==================");
            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 => {
                            console.log("ACTS_ZipFile_4900 data: " + data);
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            done();
                        }).catch(err => {
                            console.log("ACTS_ZipFile_4900 err: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_4900 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch(err => {
                    console.log("ACTS_ZipFile_4900 zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_4900 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_4900 end==================");
        })

        /*
        * @tc.number: ACTS_ZipFile_5000
        * @tc.name: zipFile
        * @tc.desc: COMPRESS_STRATEGY_FIXED,
        */
        it('ACTS_ZipFile_5000', 0, async function (done) {
            console.log("==================ACTS_ZipFile_5000 start==================");
            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 => {
                            console.log("ACTS_ZipFile_5000 data: " + data);
                            expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_OK);
                            done();
                        }).catch(err => {
                            console.log("unzipFile fail: " + err);
                            expect(err).assertFail();
                            done();
                        })
                    }).catch(function (error) {
                        console.info("ACTS_ZipFile_5000 mkdir failed with error:" + error);
                        expect(error).assertFail();
                        done();
                    });
                }).catch(err => {
                    console.log("zipFile fail: " + err);
                    expect(err).assertFail();
                    done();
                })
            }).catch(function (err) {
                console.info("ACTS_ZipFile_5000 write data to file failed with error:" + err);
                expect(err).assertFail();
                done();
            });
            console.log("==================ACTS_ZipFile_5000 end==================");
        })

        /*
I
inter515 已提交
1102 1103 1104
        * @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 已提交
1105
        */
I
inter515 已提交
1106
        it('compressFileTest', Level.LEVEL2, async function (done) {
I
inter515 已提交
1107 1108 1109 1110 1111
            console.log("==================compressFileTest start==================");
            let path1 = dir + "/compressFileTest1.txt";
            let zipDest1 = dir + "/compressFileTest1.zip";
            let path2 = dir + "/compressFileTest2.txt";
            let zipDest2 = dir + "/compressFileTest2.zip";
I
add xts  
inter515 已提交
1112 1113
            let fd = fileio.openSync(path1, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
I
inter515 已提交
1114
                console.info("compressFileTest write data to file successfully :" + number);
I
add xts  
inter515 已提交
1115
            }).catch(function (err) {
I
inter515 已提交
1116
                console.info("compressFileTest write data to file failed with error:" + err);
I
add xts  
inter515 已提交
1117 1118
                expect(err).assertFail();
            });
I
inter515 已提交
1119
            console.info("compressFileTest start compressFile");
I
add xts  
inter515 已提交
1120 1121 1122
            await zlib.compressFile(path1, zipDest1, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }).then((data) => {
I
inter515 已提交
1123
                console.info("compressFileTest data: " + JSON.stringify(data));
I
add xts  
inter515 已提交
1124 1125 1126 1127 1128 1129 1130
                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 已提交
1131
            }).catch((err) => {
I
inter515 已提交
1132
                console.info("compressFileTest data: " + JSON.stringify(err));
I
add xts  
inter515 已提交
1133
                expect(err).assertFail();
K
kirl75 已提交
1134
            })
I
add xts  
inter515 已提交
1135 1136
            let fd2 = fileio.openSync(path2, 0o100 | 0o2, 0o666);
            await fileio.write(fd2, infos).then(function (number) {
I
inter515 已提交
1137
                console.info("compressFileTest write data to file successfully :" + number);
I
add xts  
inter515 已提交
1138
            }).catch(function (err) {
I
inter515 已提交
1139
                console.info("compressFileTest write data to file failed with error:" + err);
I
add xts  
inter515 已提交
1140 1141 1142 1143 1144
                expect(err).assertFail();
            });
            zlib.compressFile(path2, zipDest2, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION
            }, (err, data) => {
I
inter515 已提交
1145 1146
                console.info("compressFileTest data2: " + JSON.stringify(data));
                console.info("compressFileTest err2: " + JSON.stringify(err));
I
add xts  
inter515 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
                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();
            })
        })
1158

I
add xts  
inter515 已提交
1159
        /*
I
inter515 已提交
1160 1161 1162
        * @tc.number: SUB_BMS_TOOL_ZLIB_0078
        * @tc.name: compressFileInFileNotExist
        * @tc.desc: test compressFile when inFile is not exist
I
add xts  
inter515 已提交
1163
        */
I
inter515 已提交
1164
        it('compressFileInFileNotExist', Level.LEVEL3, async function (done) {
I
inter515 已提交
1165 1166 1167
            console.log("==================compressFileInFileNotExist start==================");
            let path = "nonexist.txt";
            let zipDest = dir + "/compressFileInFileNotExist.zip";
I
add xts  
inter515 已提交
1168 1169 1170
            await zlib.compressFile(path, zipDest, {
                level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
            }).then((data) => {
I
inter515 已提交
1171
                console.log("compressFileInFileNotExist invalid src file success!");
I
add xts  
inter515 已提交
1172 1173 1174
                expect(data).assertFail();
                done();
            }).catch((err) => {
I
inter515 已提交
1175 1176 1177 1178 1179 1180 1181
                console.log("compressFileInFileNotExist zipFile fail: " + JSON.stringify(err));
                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 已提交
1182
                expect(err.code).assertEqual(SRC_FILE_INVALID);
I
inter515 已提交
1183
                expect(data).assertEqual(undefined);
I
add xts  
inter515 已提交
1184 1185
                done();
            })
I
inter515 已提交
1186
            console.log("==================compressFileInFileNotExist end==================");
I
add xts  
inter515 已提交
1187
        })
1188

I
add xts  
inter515 已提交
1189
        /*
I
inter515 已提交
1190 1191 1192 1193
        * @tc.number: SUB_BMS_TOOL_ZLIB_0079
        * @tc.name: compressFileInFileNull
        * @tc.desc: test compressFile when inFile is null
        */
I
inter515 已提交
1194
        it('compressFileInFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1195 1196
            console.log("==================compressFileInFileNull start==================");
            let zipDest = dir + "/compressFileInFileNull.zip";
I
inter515 已提交
1197
            try {
I
inter515 已提交
1198 1199 1200 1201 1202 1203 1204 1205 1206
                await zlib.compressFile(null, zipDest, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }).then((data) => {
                    console.log("compressFileInFileNull invalid src file success!");
                    expect().assertFail();
                }).catch((err) => {
                    console.log("compressFileInFileNull zipFile fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1207
            } catch (err) {
I
inter515 已提交
1208 1209
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1210
            try {
I
inter515 已提交
1211 1212 1213 1214 1215 1216 1217
                zlib.compressFile(null, zipDest, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }, (err, data) => {
                    console.log("compressFile result");
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1218
            } catch (err) {
I
inter515 已提交
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================compressFileInFileNull end==================");
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0081
        * @tc.name: compressFileOutFileNull
        * @tc.desc: test compressFile when outFile is null
I
add xts  
inter515 已提交
1229
        */
I
inter515 已提交
1230
        it('compressFileOutFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1231 1232 1233 1234 1235 1236 1237 1238 1239
            console.log("==================compressFileOutFileNull start==================");
            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 已提交
1240
            try {
I
inter515 已提交
1241 1242 1243 1244 1245 1246 1247 1248 1249
                await zlib.compressFile(path1, null, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }).then((data) => {
                    console.log("compressFileOutFileNull invalid src file success!");
                    expect().assertFail();
                }).catch((err) => {
                    console.log("compressFileOutFileNull zipFile fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1250
            } catch (err) {
I
inter515 已提交
1251 1252
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1253
            try {
I
inter515 已提交
1254 1255 1256 1257 1258 1259 1260
                zlib.compressFile(path1, null, {
                    level: zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION
                }, (err, data) => {
                    console.log("compressFile result");
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1261
            } catch (err) {
I
inter515 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================compressFileOutFileNull end==================");
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0082
        * @tc.name: compressFileOptionNull
        * @tc.desc: test compressFile when option is null
        */
I
inter515 已提交
1273
        it('compressFileOptionNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
            console.log("==================compressFileOptionNull start==================");
            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 已提交
1284
            try {
I
inter515 已提交
1285 1286 1287 1288 1289 1290 1291
                await zlib.compressFile(path1, zipDest1, null).then((data) => {
                    console.log("compressFileOptionNull invalid src file success!");
                    expect().assertFail();
                }).catch((err) => {
                    console.log("compressFileOptionNull zipFile fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1292
            } catch (err) {
I
inter515 已提交
1293 1294
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1295
            try {
I
inter515 已提交
1296 1297 1298 1299 1300
                zlib.compressFile(path1, zipDest1, null, (err, data) => {
                    console.log("compressFile result");
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1301
            } catch (err) {
I
inter515 已提交
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================compressFileOptionNull end==================");
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0084
        * @tc.name: compressFileStrategyNull
        * @tc.desc: test compressFile when strategy is null
        */
I
inter515 已提交
1313
        it('compressFileStrategyNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
            console.log("==================compressFileStrategyNull start==================");
            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 已提交
1324
            try {
I
inter515 已提交
1325 1326 1327 1328 1329 1330 1331 1332 1333
                await zlib.compressFile(path1, zipDest1, {
                    strategy: null
                }).then((data) => {
                    console.log("compressFileStrategyNull invalid src file success!");
                    expect().assertFail();
                }).catch((err) => {
                    console.log("compressFileStrategyNull zipFile fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1334
            } catch (err) {
I
inter515 已提交
1335 1336
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1337
            try {
I
inter515 已提交
1338 1339 1340 1341 1342 1343 1344
                zlib.compressFile(path1, zipDest1, {
                    strategy: null
                }, (err, data) => {
                    console.log("compressFile result");
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1345
            } catch (err) {
I
inter515 已提交
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================compressFileOutFileNull end==================");
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0087
        * @tc.name: decompressFileTest
        * @tc.desc: test decompressFile when inFile and out file is valid
        */
I
inter515 已提交
1357
        it('decompressFileTest', Level.LEVEL2, async function (done) {
I
inter515 已提交
1358 1359 1360 1361 1362 1363 1364 1365
            console.log("==================decompressFileTest start==================");
            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 已提交
1366 1367
            let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
            await fileio.write(fd, infos).then(function (number) {
I
inter515 已提交
1368
                console.info("decompressFileTest write data to file success " + JSON.stringify(number));
I
add xts  
inter515 已提交
1369
            }).catch(function (err) {
I
inter515 已提交
1370
                console.info("decompressFileTest write data to file failed with error:" + err);
I
add xts  
inter515 已提交
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
                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 已提交
1404
                console.info("decompressFileTest mkdir successfully");
I
add xts  
inter515 已提交
1405
            }).catch(function (error) {
I
inter515 已提交
1406
                console.info("decompressFileTest mkdir failed with error:" + error);
I
add xts  
inter515 已提交
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
                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 已提交
1422
                console.info("decompressFileTest mkdir successfully");
I
add xts  
inter515 已提交
1423
            }).catch(function (error) {
I
inter515 已提交
1424
                console.info("decompressFileTest mkdir failed with error:" + error);
I
add xts  
inter515 已提交
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
                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();
            })
        })
1440

I
add xts  
inter515 已提交
1441
        /*
I
inter515 已提交
1442 1443 1444
        * @tc.number: SUB_BMS_TOOL_ZLIB_0088
        * @tc.name: decompressFileInFileNotExist
        * @tc.desc: test decompressFile when inFile is not exist
I
add xts  
inter515 已提交
1445
        */
I
inter515 已提交
1446
        it('decompressFileInFileNotExist', Level.LEVEL3, async function (done) {
I
inter515 已提交
1447 1448 1449
            console.log("==================decompressFileInFileNotExist start==================");
            let zipDest = dir + "/noneexist.zip";
            let unzipdir = dir + "/decompressFileInFileNotExist";
I
add xts  
inter515 已提交
1450
            await fileio.mkdir(unzipdir).then(function () {
I
inter515 已提交
1451
                console.info("fileio mkdir successfully");
I
add xts  
inter515 已提交
1452
            }).catch(function (error) {
I
inter515 已提交
1453
                console.info("fileio mkdir failed with error:" + error);
I
add xts  
inter515 已提交
1454 1455 1456 1457 1458
                expect(error).assertFail();
            });
            await zlib.decompressFile(zipDest, unzipdir, {
                strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
            }).then(data => {
I
inter515 已提交
1459
                console.log("decompressFile data: " + data);
I
add xts  
inter515 已提交
1460 1461 1462 1463 1464 1465 1466
                expect(data).assertFail(null);
                done();
            }).catch(err => {
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(SRC_FILE_INVALID);
                done();
            })
I
inter515 已提交
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
            zlib.decompressFile(zipDest, unzipdir, {
                strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
            }, (err, data) => {
                expect(err.code).assertEqual(SRC_FILE_INVALID);
                expect(data).assertEqual(undefined);
                done();
            })
            console.log("==================decompressFileInFileNotExist end==================");
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0089
        * @tc.name: decompressFileInFileNull
        * @tc.desc: test decompressFile when inFile is null
        */
I
inter515 已提交
1482
        it('decompressFileInFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1483 1484 1485 1486 1487 1488 1489 1490
            console.log("==================decompressFileInFileNull start==================");
            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 已提交
1491
            try {
I
inter515 已提交
1492 1493 1494 1495 1496 1497 1498 1499 1500
                await zlib.decompressFile(null, unzipdir, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }).then(data => {
                    console.log("decompressFile data: " + data);
                    expect().assertFail();
                }).catch(err => {
                    console.log("decompress fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1501
            } catch (err) {
I
inter515 已提交
1502 1503 1504
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1505
            try {
I
inter515 已提交
1506 1507 1508 1509 1510 1511
                zlib.decompressFile(null, unzipdir, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }, (err, data) => {
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1512
            } catch (err) {
I
inter515 已提交
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================decompressFileInFileNull end==================");
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0091
        * @tc.name: decompressFileOutFileNull
        * @tc.desc: test decompressFile when outFile is null
        */
I
inter515 已提交
1525
        it('decompressFileOutFileNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
            console.log("==================decompressFileOutFileNull start==================");
            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 已提交
1551
            try {
I
inter515 已提交
1552 1553 1554 1555 1556 1557 1558 1559 1560
                await zlib.decompressFile(zipDest1, null, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }).then(data => {
                    console.log("decompressFile data: " + data);
                    expect().assertFail();
                }).catch(err => {
                    console.log("decompress fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1561
            } catch (err) {
I
inter515 已提交
1562 1563 1564
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1565
            try {
I
inter515 已提交
1566 1567 1568 1569 1570 1571
                zlib.decompressFile(zipDest1, null, {
                    strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED
                }, (err, data) => {
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1572
            } catch (err) {
I
inter515 已提交
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================decompressFileOutFileNull end==================");
        })

        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0092
        * @tc.name: decompressFileOptionNull
        * @tc.desc: test decompressFile when option is null
        */
I
inter515 已提交
1585
        it('decompressFileOptionNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
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
            console.log("==================decompressFileOptionNull start==================");
            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 已提交
1618
            try {
I
inter515 已提交
1619 1620 1621 1622 1623 1624 1625
                await zlib.decompressFile(zipDest1, unzipdir, null).then(data => {
                    console.log("decompressFile data: " + data);
                    expect().assertFail();
                }).catch(err => {
                    console.log("decompress fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1626
            } catch (err) {
I
inter515 已提交
1627 1628 1629
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1630
            try {
I
inter515 已提交
1631 1632 1633 1634
                zlib.decompressFile(zipDest1, unzipdir, null, (err, data) => {
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1635
            } catch (err) {
I
inter515 已提交
1636 1637 1638 1639 1640
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================decompressFileOutFileNull end==================");
1641 1642
        })

I
inter515 已提交
1643 1644 1645 1646 1647
        /*
        * @tc.number: SUB_BMS_TOOL_ZLIB_0094
        * @tc.name: decompressFileStrategyNull
        * @tc.desc: test decompressFile when strategy is null
        */
I
inter515 已提交
1648
        it('decompressFileStrategyNull', Level.LEVEL3, async function (done) {
I
inter515 已提交
1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
            console.log("==================decompressFileStrategyNull start==================");
            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 已提交
1681
            try {
I
inter515 已提交
1682 1683 1684 1685 1686 1687 1688 1689 1690
                await zlib.decompressFile(zipDest1, unzipdir, {
                    strategy: null
                }).then(data => {
                    console.log("decompressFile data: " + data);
                    expect().assertFail();
                }).catch(err => {
                    console.log("decompress fail: " + JSON.stringify(err));
                    expect().assertFail();
                })
I
inter515 已提交
1691
            } catch (err) {
I
inter515 已提交
1692 1693 1694
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
            }
I
inter515 已提交
1695
            try {
I
inter515 已提交
1696 1697 1698 1699 1700 1701
                zlib.decompressFile(zipDest1, unzipdir, {
                    strategy: null
                }, (err, data) => {
                    expect().assertFail();
                    done();
                })
I
inter515 已提交
1702
            } catch (err) {
I
inter515 已提交
1703 1704 1705 1706 1707 1708
                console.log("decompress fail: " + JSON.stringify(err));
                expect(err.code).assertEqual(PARAM_ERROR);
                done();
            }
            console.log("==================decompressFileStrategyNull end==================");
        })
1709
    })
J
jiyong_sd 已提交
1710
}
K
kirl75 已提交
1711