-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeflate_cover.js
90 lines (71 loc) · 2.64 KB
/
deflate_cover.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
// Deflate coverage tests
'use strict';
import { assert, describe, it } from 'vitest';
import fs from 'fs';
import path from 'path';
import * as pako from '../lib/main';
import * as c from '../lib/zlib/constants';
import msg from '../lib/zlib/messages';
import * as zlib_deflate from '../lib/zlib/deflate';
import ZStream from '../lib/zlib/zstream';
var short_sample = 'hello world';
var long_sample = fs.readFileSync(path.join(__dirname, 'fixtures/samples/lorem_en_100k.txt'));
function testDeflate(data, opts, flush) {
var deflator = new pako.Deflate(opts);
deflator.push(data, flush);
deflator.push(data, true);
assert.equal(deflator.err, false, msg[deflator.err]);
}
describe('Deflate support', function () {
it('stored', function () {
testDeflate(short_sample, { level: 0, chunkSize: 200 }, 0);
testDeflate(short_sample, { level: 0, chunkSize: 10 }, 5);
});
it('fast', function () {
testDeflate(short_sample, { level: 1, chunkSize: 10 }, 5);
testDeflate(long_sample, { level: 1, memLevel: 1, chunkSize: 10 }, 0);
});
it('slow', function () {
testDeflate(short_sample, { level: 4, chunkSize: 10 }, 5);
testDeflate(long_sample, { level: 9, memLevel: 1, chunkSize: 10 }, 0);
});
it('rle', function () {
testDeflate(short_sample, { strategy: 3 }, 0);
testDeflate(short_sample, { strategy: 3, chunkSize: 10 }, 5);
testDeflate(long_sample, { strategy: 3, chunkSize: 10 }, 0);
});
it('huffman', function () {
testDeflate(short_sample, { strategy: 2 }, 0);
testDeflate(short_sample, { strategy: 2, chunkSize: 10 }, 5);
testDeflate(long_sample, { strategy: 2, chunkSize: 10 }, 0);
});
});
describe('Deflate states', function () {
//in port checking input parameters was removed
it('inflate bad parameters', function () {
var ret, strm;
ret = zlib_deflate.deflate(null, 0);
assert(ret === c.Z_STREAM_ERROR);
strm = new ZStream();
ret = zlib_deflate.deflateInit(null);
assert(ret === c.Z_STREAM_ERROR);
ret = zlib_deflate.deflateInit(strm, 6);
assert(ret === c.Z_OK);
ret = zlib_deflate.deflateSetHeader(null);
assert(ret === c.Z_STREAM_ERROR);
strm.state.wrap = 1;
ret = zlib_deflate.deflateSetHeader(strm, null);
assert(ret === c.Z_STREAM_ERROR);
strm.state.wrap = 2;
ret = zlib_deflate.deflateSetHeader(strm, null);
assert(ret === c.Z_OK);
ret = zlib_deflate.deflate(strm, c.Z_FINISH);
assert(ret === c.Z_BUF_ERROR);
ret = zlib_deflate.deflateEnd(null);
assert(ret === c.Z_STREAM_ERROR);
//BS_NEED_MORE
strm.state.status = 5;
ret = zlib_deflate.deflateEnd(strm);
assert(ret === c.Z_STREAM_ERROR);
});
});