actszipfileandunzipfiletest.test.js 40.8 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'
K
kirl75 已提交
19
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
R
renyi 已提交
20 21
var dir = "";
var infos = "";
K
kirl75 已提交
22 23

describe('ActsZlibTest', function () {
R
renyi 已提交
24 25 26 27 28 29 30
    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";
R
renyi 已提交
31
       var objectthree ="com.example.amsZipfileUnzipfileST.MainAbility/ActsZlibTest/example.amsZipfileUnzipfileST";
R
renyi 已提交
32 33 34 35
        infos =dir + objectone + objecttwo + objectthree;
        done();
      })
    });
K
kirl75 已提交
36

K
kirl75 已提交
37 38 39 40 41 42
/*
* @tc.number: ACTS_ZipFile_0100
* @tc.name: zipFile
* @tc.desc: inFile is empty
*/
it('ACTS_ZipFile_0100', 0, async function (done) {
R
renyi 已提交
43 44
    console.log("==================ACTS_ZipFile_0100 start==================");
    var path ="";
K
kirl75 已提交
45 46
    var zipDest = dir + "/ACTS_ZipFile_0100.zip"
    var options = {};
R
renyi 已提交
47
    options.level = zlib.CompressLevel.COMPRESS_LEVEL_NO_COMPRESSION;
R
renyi 已提交
48 49 50 51 52 53 54 55 56 57
    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("zipFile fail: " + err);
      expect(err).assertFail();
      done();
    })
  })
K
kirl75 已提交
58 59 60 61 62 63 64

/*
* @tc.number: ACTS_ZipFile_0200
* @tc.name: zipFile
* @tc.desc: inFile doesn't exist
*/
it('ACTS_ZipFile_0200', 0, async function (done) {
R
renyi 已提交
65 66 67 68
    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);
K
kirl75 已提交
69
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
70 71
      console.info("ACTS_ZipFile_0200 write data to file successfully:" + number);
      var options = {};
R
renyi 已提交
72
      options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION;
R
renyi 已提交
73 74 75 76 77 78 79 80 81
      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("zipFile fail: " + err);
        expect(err).assertFail();
        done();
      })
K
kirl75 已提交
82
    }).catch(function (err) {
R
renyi 已提交
83 84
      console.info("ACTS_ZipFile_0200 write data to file failed with error:" + err);
      done();
K
kirl75 已提交
85
    });
R
renyi 已提交
86
  })
K
kirl75 已提交
87 88 89 90 91 92 93

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

/*
* @tc.number: ACTS_ZipFile_0400
* @tc.name: zipFile
* @tc.desc: The ouput file is a directory that does not exist
*/
it('ACTS_ZipFile_0400', 0, async function (done) {
R
renyi 已提交
123 124 125 126
    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);
K
kirl75 已提交
127
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
128 129
      console.info("ACTS_ZipFile_0400 write data to file successfully:" + number);
      var options = {};
R
renyi 已提交
130
      options.level = zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION;
R
renyi 已提交
131 132 133 134 135 136 137 138 139
      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("zipFile fail: " + err);
        expect(err).assertFail();
        done();
      })
K
kirl75 已提交
140
    }).catch(function (err) {
R
renyi 已提交
141 142
      console.info("ACTS_ZipFile_0400 write data to file failed with error:" + err);
      done();
K
kirl75 已提交
143
    });
R
renyi 已提交
144
  })
K
kirl75 已提交
145 146

/*
R
add api  
r00559040 已提交
147
* @tc.number: ACTS_ZipFile_2200
K
kirl75 已提交
148
* @tc.name: zipFile
R
add api  
r00559040 已提交
149
* @tc.desc: COMPRESS_LEVEL_NO_COMPRESSION,
K
kirl75 已提交
150
*/
R
add api  
r00559040 已提交
151 152
it('ACTS_ZipFile_2200', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2200 start==================");
R
renyi 已提交
153
    var path = dir + "/ACTS_ZipFile_2200.txt";
R
add api  
r00559040 已提交
154
    var zipDest = dir + "/ACTS_ZipFile_2200.zip"
R
renyi 已提交
155 156 157 158 159
    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);
K
kirl75 已提交
160
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
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
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_2200 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
194
    }).catch(function (err) {
R
add api  
r00559040 已提交
195
        console.info("ACTS_ZipFile_2200 write data to file failed with error:" + err);
K
kirl75 已提交
196
    });
R
add api  
r00559040 已提交
197
    console.log("==================ACTS_ZipFile_2200 end==================");
R
renyi 已提交
198
  });
K
kirl75 已提交
199 200

/*
R
add api  
r00559040 已提交
201
* @tc.number: ACTS_ZipFile_2300
K
kirl75 已提交
202
* @tc.name: zipFile
R
add api  
r00559040 已提交
203
* @tc.desc: COMPRESS_LEVEL_BEST_SPEED,
K
kirl75 已提交
204
*/
R
add api  
r00559040 已提交
205 206
it('ACTS_ZipFile_2300', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2300 start==================");
R
renyi 已提交
207
    var path = dir + "/ACTS_ZipFile_2300.txt";
R
add api  
r00559040 已提交
208
    var zipDest = dir + "/ACTS_ZipFile_2300.zip"
R
renyi 已提交
209 210 211 212 213
    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);
K
kirl75 已提交
214
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
215 216 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
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_2300 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
248
    }).catch(function (err) {
R
renyi 已提交
249
        console.info("ACTS_ZipFile_2200 write data to file failed with error:" + err);
K
kirl75 已提交
250
    });
R
renyi 已提交
251 252
     console.log("==================ACTS_ZipFile_2300 end==================");
  })
K
kirl75 已提交
253 254

/*
R
add api  
r00559040 已提交
255
* @tc.number: ACTS_ZipFile_2400
K
kirl75 已提交
256
* @tc.name: zipFile
R
add api  
r00559040 已提交
257
* @tc.desc: COMPRESS_LEVEL_BEST_COMPRESSION,
K
kirl75 已提交
258
*/
R
add api  
r00559040 已提交
259 260
it('ACTS_ZipFile_2400', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2400 start==================");
R
renyi 已提交
261
    var path = dir + "/ACTS_ZipFile_2400.txt";
R
add api  
r00559040 已提交
262
    var zipDest = dir + "/ACTS_ZipFile_2400.zip"
R
renyi 已提交
263 264 265 266 267
    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);
K
kirl75 已提交
268
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
269 270 271 272 273 274 275 276 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
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_2400 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
302
    }).catch(function (err) {
R
add api  
r00559040 已提交
303
        console.info("ACTS_ZipFile_2400 write data to file failed with error:" + err);
K
kirl75 已提交
304
    });
R
add api  
r00559040 已提交
305
    console.log("==================ACTS_ZipFile_2400 end==================");
R
renyi 已提交
306
  });
K
kirl75 已提交
307 308

/*
R
add api  
r00559040 已提交
309
* @tc.number: ACTS_ZipFile_2500
K
kirl75 已提交
310
* @tc.name: zipFile
R
add api  
r00559040 已提交
311
* @tc.desc: COMPRESS_LEVEL_DEFAULT_COMPRESSION,
K
kirl75 已提交
312
*/
R
add api  
r00559040 已提交
313 314
it('ACTS_ZipFile_2500', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2500 start==================");
R
renyi 已提交
315
    var path = dir + "/ACTS_ZipFile_2500.txt";
R
add api  
r00559040 已提交
316
    var zipDest = dir + "/ACTS_ZipFile_2500.zip"
R
renyi 已提交
317 318 319 320 321
    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);
K
kirl75 已提交
322
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
      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);
            done()
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_2500 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
356
    }).catch(function (err) {
R
add api  
r00559040 已提交
357
        console.info("ACTS_ZipFile_2500 write data to file failed with error:" + err);
K
kirl75 已提交
358
    });
R
add api  
r00559040 已提交
359
    console.log("==================ACTS_ZipFile_2500 end==================");
R
renyi 已提交
360
  });
K
kirl75 已提交
361 362

/*
R
add api  
r00559040 已提交
363
* @tc.number: ACTS_ZipFile_2600
K
kirl75 已提交
364
* @tc.name: zipFile
R
add api  
r00559040 已提交
365
* @tc.desc: MEM_LEVEL_MIN_MEMLEVEL,,
K
kirl75 已提交
366
*/
R
add api  
r00559040 已提交
367 368
it('ACTS_ZipFile_2600', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2600 start==================");
R
renyi 已提交
369
    var path = dir + "/ACTS_ZipFile_2600.txt";
R
add api  
r00559040 已提交
370
    var zipDest = dir + "/ACTS_ZipFile_2600.zip"
R
renyi 已提交
371 372 373 374 375
    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);
K
kirl75 已提交
376
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_2600 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
410
    }).catch(function (err) {
R
add api  
r00559040 已提交
411
        console.info("ACTS_ZipFile_2600 write data to file failed with error:" + err);
K
kirl75 已提交
412
    });
R
add api  
r00559040 已提交
413
    console.log("==================ACTS_ZipFile_2600 end==================");
R
renyi 已提交
414
  });
K
kirl75 已提交
415 416

/*
R
add api  
r00559040 已提交
417
* @tc.number: ACTS_ZipFile_2700
K
kirl75 已提交
418
* @tc.name: zipFile
R
add api  
r00559040 已提交
419
* @tc.desc: MEM_LEVEL_MAX_MEMLEVEL,,
K
kirl75 已提交
420
*/
R
add api  
r00559040 已提交
421 422
it('ACTS_ZipFile_2700', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2700 start==================");
R
renyi 已提交
423
    var path = dir + "/ACTS_ZipFile_2700.txt";
R
add api  
r00559040 已提交
424
    var zipDest = dir + "/ACTS_ZipFile_2700.zip"
R
renyi 已提交
425 426 427 428 429
    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);
K
kirl75 已提交
430
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_2700 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
         expect(err).assertFail();
      })
K
kirl75 已提交
464
    }).catch(function (err) {
R
add api  
r00559040 已提交
465
        console.info("ACTS_ZipFile_2700 write data to file failed with error:" + err);
K
kirl75 已提交
466
    });
R
add api  
r00559040 已提交
467
    console.log("==================ACTS_ZipFile_2700 end==================");
R
renyi 已提交
468
  });
K
kirl75 已提交
469 470

/*
R
add api  
r00559040 已提交
471
* @tc.number: ACTS_ZipFile_2800
K
kirl75 已提交
472
* @tc.name: zipFile
R
add api  
r00559040 已提交
473
* @tc.desc: MEM_LEVEL_DEFAULT_MEMLEVEL,,
K
kirl75 已提交
474
*/
R
add api  
r00559040 已提交
475 476
it('ACTS_ZipFile_2800', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2800 start==================");
R
renyi 已提交
477
    var path = dir + "/ACTS_ZipFile_2800.txt";
R
add api  
r00559040 已提交
478
    var zipDest = dir + "/ACTS_ZipFile_2800.zip"
R
renyi 已提交
479 480 481 482 483
    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);
K
kirl75 已提交
484
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
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 515 516 517
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_2800 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
518
    }).catch(function (err) {
R
add api  
r00559040 已提交
519
        console.info("ACTS_ZipFile_2800 write data to file failed with error:" + err);
K
kirl75 已提交
520
    });
R
add api  
r00559040 已提交
521
    console.log("==================ACTS_ZipFile_2800 end==================");
R
renyi 已提交
522
  });
K
kirl75 已提交
523 524

/*
R
add api  
r00559040 已提交
525
* @tc.number: ACTS_ZipFile_2900
K
kirl75 已提交
526
* @tc.name: zipFile
R
add api  
r00559040 已提交
527
* @tc.desc: COMPRESS_STRATEGY_DEFAULT_STRATEGY,,
K
kirl75 已提交
528
*/
R
add api  
r00559040 已提交
529 530
it('ACTS_ZipFile_2900', 0, async function (done) {
    console.log("==================ACTS_ZipFile_2900 start==================");
R
renyi 已提交
531
    var path = dir + "/ACTS_ZipFile_2900.txt";
R
add api  
r00559040 已提交
532
    var zipDest = dir + "/ACTS_ZipFile_2900.zip"
R
renyi 已提交
533 534 535 536 537
    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);
K
kirl75 已提交
538
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
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
      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);
              done();
            })
          }).catch(function (error) {
            console.info("ACTS_ZipFile_2900 mkdir failed with error:" + error);
          });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
572
    }).catch(function (err) {
R
add api  
r00559040 已提交
573
        console.info("ACTS_ZipFile_2900 write data to file failed with error:" + err);
K
kirl75 已提交
574
    });
R
add api  
r00559040 已提交
575
    console.log("==================ACTS_ZipFile_2900 end==================");
R
renyi 已提交
576
  });
K
kirl75 已提交
577 578

/*
R
add api  
r00559040 已提交
579
* @tc.number: ACTS_ZipFile_3000
K
kirl75 已提交
580
* @tc.name: zipFile
R
add api  
r00559040 已提交
581
* @tc.desc: COMPRESS_STRATEGY_FILTERED,,
K
kirl75 已提交
582
*/
R
add api  
r00559040 已提交
583 584
it('ACTS_ZipFile_3000', 0, async function (done) {
    console.log("==================ACTS_ZipFile_3000 start==================");
R
renyi 已提交
585
    var path = dir + "/ACTS_ZipFile_3000.txt";
R
add api  
r00559040 已提交
586
    var zipDest = dir + "/ACTS_ZipFile_3000.zip"
R
renyi 已提交
587 588 589 590 591
    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);
K
kirl75 已提交
592
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
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
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_3000 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
626
    }).catch(function (err) {
R
add api  
r00559040 已提交
627
        console.info("ACTS_ZipFile_3000 write data to file failed with error:" + err);
K
kirl75 已提交
628
    });
R
add api  
r00559040 已提交
629
    console.log("==================ACTS_ZipFile_3000 end==================");
R
renyi 已提交
630
  });
K
kirl75 已提交
631 632

/*
R
add api  
r00559040 已提交
633
* @tc.number: ACTS_ZipFile_3100
K
kirl75 已提交
634
* @tc.name: zipFile
R
add api  
r00559040 已提交
635
* @tc.desc: COMPRESS_STRATEGY_HUFFMAN_ONLY,,
K
kirl75 已提交
636
*/
R
add api  
r00559040 已提交
637 638
it('ACTS_ZipFile_3100', 0, async function (done) {
    console.log("==================ACTS_ZipFile_3100 start==================");
R
renyi 已提交
639
    var path = dir + "/ACTS_ZipFile_3100.txt";
R
add api  
r00559040 已提交
640
    var zipDest = dir + "/ACTS_ZipFile_3100.zip"
R
renyi 已提交
641 642 643 644 645
    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);
K
kirl75 已提交
646
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
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
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_3100 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
680
    }).catch(function (err) {
R
add api  
r00559040 已提交
681
        console.info("ACTS_ZipFile_3100 write data to file failed with error:" + err);
K
kirl75 已提交
682
    });
R
add api  
r00559040 已提交
683
    console.log("==================ACTS_ZipFile_3100 end==================");
R
renyi 已提交
684
  });
K
kirl75 已提交
685 686

/*
R
add api  
r00559040 已提交
687
* @tc.number: ACTS_ZipFile_3200
K
kirl75 已提交
688
* @tc.name: zipFile
R
add api  
r00559040 已提交
689
* @tc.desc: COMPRESS_STRATEGY_RLE,,
K
kirl75 已提交
690
*/
R
add api  
r00559040 已提交
691 692
it('ACTS_ZipFile_3200', 0, async function (done) {
    console.log("==================ACTS_ZipFile_3200 start==================");
R
renyi 已提交
693 694 695 696 697 698 699
    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);
K
kirl75 已提交
700
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
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
      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();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_3200 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
733
    }).catch(function (err) {
R
add api  
r00559040 已提交
734
        console.info("ACTS_ZipFile_3200 write data to file failed with error:" + err);
K
kirl75 已提交
735
    });
R
add api  
r00559040 已提交
736
    console.log("==================ACTS_ZipFile_3200 end==================");
R
renyi 已提交
737
  });
K
kirl75 已提交
738 739

/*
R
add api  
r00559040 已提交
740
* @tc.number: ACTS_ZipFile_3300
K
kirl75 已提交
741
* @tc.name: zipFile
R
add api  
r00559040 已提交
742
* @tc.desc: COMPRESS_STRATEGY_FILTERED,,
K
kirl75 已提交
743
*/
R
add api  
r00559040 已提交
744 745
it('ACTS_ZipFile_3300', 0, async function (done) {
    console.log("==================ACTS_ZipFile_3300 start==================");
R
renyi 已提交
746
    var path = dir + "/ACTS_ZipFile_3300.txt";
R
add api  
r00559040 已提交
747
    var zipDest = dir + "/ACTS_ZipFile_3300.zip"
R
renyi 已提交
748 749 750 751 752
    var unzipdir = dir + "/ACTS_ZipFile_3300";
    var unzipresultfile = unzipdir + "/ACTS_ZipFile_3300.txt";
    var options = {};
    options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
    var fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
K
kirl75 已提交
753
    fileio.write(fd, infos).then(function (number) {
R
renyi 已提交
754 755 756 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
      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);
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_3300 mkdir failed with error:" + error);
        });
      }).catch((err) => {
          console.log("zipFile fail: " + err);
          expect(err).assertFail();
      })
K
kirl75 已提交
787
    }).catch(function (err) {
R
add api  
r00559040 已提交
788
        console.info("ACTS_ZipFile_3300 write data to file failed with error:" + err);
K
kirl75 已提交
789
    });
R
add api  
r00559040 已提交
790
    console.log("==================ACTS_ZipFile_3300 end==================");
R
renyi 已提交
791
  });
K
kirl75 已提交
792 793

/*
R
add api  
r00559040 已提交
794
* @tc.number: ACTS_ZipFile_3500
K
kirl75 已提交
795 796 797
* @tc.name: zipFile
* @tc.desc: FLUSH_TYPE_NO_FLUSH,,
*/
R
add api  
r00559040 已提交
798 799
it('ACTS_ZipFile_3500', 0, async function (done) {
    console.log("==================ACTS_ZipFile_3500 start==================");
R
renyi 已提交
800 801 802
    var path = dir + "/ACTS_ZipFile_3500.txt";
    var src = dir + "/ACTS_ZipFile_9900.txt";
    var unzipdir = dir + "/ACTS_ZipFile_3500";
R
add api  
r00559040 已提交
803
    var options = {};
R
renyi 已提交
804 805 806 807 808
    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) => {
R
add api  
r00559040 已提交
809 810 811
        console.log("zipFilePromise_3500 data: " + data);
        expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
        done();
R
renyi 已提交
812
      }).catch((err) => {
R
add api  
r00559040 已提交
813
        console.log("zipFilePromise_3500 err: " + err);
K
kirl75 已提交
814
        done();
R
renyi 已提交
815 816 817
      });
    }).catch(function (err) {
      console.info("ACTS_ZipFile_3500 write data to file failed with error:" + err);
K
kirl75 已提交
818
    });
R
add api  
r00559040 已提交
819
    console.log("==================zipFilePromise_3500 end ==================");
R
renyi 已提交
820
  })
K
kirl75 已提交
821 822

/*
R
add api  
r00559040 已提交
823
* @tc.number: ACTS_ZipFile_3600
K
kirl75 已提交
824 825 826
* @tc.name: zipFile
* @tc.desc: FLUSH_TYPE_NO_FLUSH,,
*/
R
add api  
r00559040 已提交
827 828
it('ACTS_ZipFile_3600', 0, async function (done) {
    console.log("==================ACTS_ZipFile_3600 start==================");
R
renyi 已提交
829
    var path = dir + "/ACTS_ZipFile_3600.txt";
R
add api  
r00559040 已提交
830
    var zipDest = "";
K
kirl75 已提交
831
    var options = {};
R
renyi 已提交
832 833 834 835 836
    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) => {
R
add api  
r00559040 已提交
837 838 839
        console.log("zipFilePromise_3600 data: " + data);
        expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
        done();
R
renyi 已提交
840
      }).catch((err) => {
R
add api  
r00559040 已提交
841 842
        console.log("zipFilePromise_3600 err: " + err);
        done();
R
renyi 已提交
843 844 845
      });
    }).catch(function (err) {
      console.info("ACTS_ZipFile_3600 write data to file failed with error:" + err);
R
add api  
r00559040 已提交
846 847
    });
    console.log("==================zipFilePromise_3600 end ==================")
R
renyi 已提交
848
  })
K
kirl75 已提交
849 850 851 852

/*
* @tc.number: ACTS_ZipFile_4500
* @tc.name: zipFile
R
add api  
r00559040 已提交
853
* @tc.desc: COMPRESS_STRATEGY_FILTERED,,
K
kirl75 已提交
854 855
*/
it('ACTS_ZipFile_4500', 0, async function (done) {
R
renyi 已提交
856 857
    console.log("==================ACTS_ZipFile_4500 start==================");
    var path = dir + "/ACTS_ZipFile_4500.txt";
K
kirl75 已提交
858 859
    var zipDest = dir + "/ACTS_ZipFile_4500.zip"
    var unzipDest = dir + "/ACTS_ZipFile_9900.zip"
R
renyi 已提交
860 861
    var unzipdir = dir + "/ACTS_ZipFile_4500";
    var zipdir = dir + "/ACTS_ZipFile_9900";
K
kirl75 已提交
862
    var options = {};
K
kirl75 已提交
863
    options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
R
renyi 已提交
864 865 866 867 868 869 870 871 872 873 874 875 876
    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");
K
kirl75 已提交
877
            zlib.unzipFile(unzipDest, zipdir, options).then((data) => {
R
renyi 已提交
878 879 880
              console.log("ACTS_ZipFile_4500 data: " + data);
              expect(data).assertEqual(zlib.ErrorCode.ERROR_CODE_ERRNO);
              done();
K
kirl75 已提交
881
            }).catch((err) => {
R
renyi 已提交
882 883
              console.log("ACTS_ZipFile_4500 err: " + err);
              done();
K
kirl75 已提交
884
            })
R
renyi 已提交
885 886 887 888 889 890 891 892 893 894 895
          }).catch(function (error) {
            console.info("ACTS_ZipFile_4500 mkdir failed with error:" + error);
          });
      }).catch((err) => {
         console.log("zipFile fail: " + err);
         expect(err).assertFail();
      })
    }).catch(function (err) {
        console.info("ACTS_ZipFile_4500 write data to file failed with error:" + err);
    });
  })
K
kirl75 已提交
896 897

/*
R
add api  
r00559040 已提交
898
* @tc.number: ACTS_ZipFile_4900
K
kirl75 已提交
899
* @tc.name: zipFile
R
add api  
r00559040 已提交
900
* @tc.desc: COMPRESS_STRATEGY_FILTERED,
K
kirl75 已提交
901
*/
R
add api  
r00559040 已提交
902 903
it('ACTS_ZipFile_4900', 0, async function (done) {
    console.log("==================ACTS_ZipFile_4900 start==================");
R
renyi 已提交
904
    var path = dir + "/ACTS_ZipFile_4900.txt";
R
add api  
r00559040 已提交
905 906
    var zipDest = dir + "/ACTS_ZipFile_4900.zip"
    var unzipDest = dir + "/ACTS_ZipFile_4900.zip"
R
renyi 已提交
907 908
    var unzipdir = dir + "/ACTS_ZipFile_4900";
    var zipdir = dir + "/ACTS_ZipFile_4900";
K
kirl75 已提交
909
    var options = {};
R
add api  
r00559040 已提交
910
    options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FILTERED;
R
renyi 已提交
911 912 913 914
    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 => {
R
add api  
r00559040 已提交
915 916 917 918 919 920 921
        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);
R
renyi 已提交
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
        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("unzipFile fail: " + err);
            expect(err).assertFail();
            done();
          })
        }).catch(function (error) {
          console.info("ACTS_ZipFile_4900 mkdir failed with error:" + error);
        });
      }).catch(err => {
R
add api  
r00559040 已提交
937 938
        console.log("zipFile fail: " + err);
        expect(err).assertFail();
R
renyi 已提交
939 940 941
      })
    }).catch(function (err) {
      console.info("ACTS_ZipFile_4900 write data to file failed with error:" + err);
R
add api  
r00559040 已提交
942
    });
R
renyi 已提交
943
})
R
add api  
r00559040 已提交
944
    
K
kirl75 已提交
945
/*
R
add api  
r00559040 已提交
946
* @tc.number: ACTS_ZipFile_5000
K
kirl75 已提交
947
* @tc.name: zipFile
R
add api  
r00559040 已提交
948
* @tc.desc: COMPRESS_STRATEGY_FIXED,
K
kirl75 已提交
949
*/
R
add api  
r00559040 已提交
950 951
it('ACTS_ZipFile_5000', 0, async function (done) {
    console.log("==================ACTS_ZipFile_5000 start==================");
R
renyi 已提交
952
    var path = dir + "/ACTS_ZipFile_5000.txt";
R
add api  
r00559040 已提交
953
    var zipDest = dir + "/ACTS_ZipFile_5000.zip"
R
renyi 已提交
954
    var unzipdir = dir + "/ACTS_ZipFile_5000";
K
kirl75 已提交
955
    var options = {};
R
add api  
r00559040 已提交
956
    options.strategy = zlib.CompressStrategy.COMPRESS_STRATEGY_FIXED;
R
renyi 已提交
957 958 959 960
    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 => {
R
add api  
r00559040 已提交
961 962 963 964 965 966 967
        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);
R
renyi 已提交
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
        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);
        });
      }).catch(err => {
R
add api  
r00559040 已提交
983 984
        console.log("zipFile fail: " + err);
        expect(err).assertFail();
R
renyi 已提交
985 986 987
      })
    }).catch(function (err) {
      console.info("ACTS_ZipFile_5000 write data to file failed with error:" + err);
R
add api  
r00559040 已提交
988
    });
K
kirl75 已提交
989 990 991 992
    })
})