1
// Deflate coverage tests
3
/*global describe, it*/
9
var assert = require('assert');
10
var fs = require('fs');
11
var path = require('path');
13
var c = require('../lib/zlib/constants');
14
var msg = require('../lib/zlib/messages');
15
var zlib_deflate = require('../lib/zlib/deflate.js');
16
var zstream = require('../lib/zlib/zstream');
18
var pako = require('../index');
21
var short_sample = 'hello world';
22
var long_sample = fs.readFileSync(path.join(__dirname, 'fixtures/samples/lorem_en_100k.txt'));
24
function testDeflate(data, opts, flush) {
25
var deflator = new pako.Deflate(opts);
26
deflator.push(data, flush);
27
deflator.push(data, true);
29
assert.equal(deflator.err, false, msg[deflator.err]);
32
describe('Deflate support', function() {
33
it('stored', function() {
34
testDeflate(short_sample, {level: 0, chunkSize: 200}, 0);
35
testDeflate(short_sample, {level: 0, chunkSize: 10}, 5);
37
it('fast', function() {
38
testDeflate(short_sample, {level: 1, chunkSize: 10}, 5);
39
testDeflate(long_sample, {level: 1, memLevel: 1, chunkSize: 10}, 0);
41
it('slow', function() {
42
testDeflate(short_sample, {level: 4, chunkSize: 10}, 5);
43
testDeflate(long_sample, {level: 9, memLevel: 1, chunkSize: 10}, 0);
45
it('rle', function() {
46
testDeflate(short_sample, {strategy: 3}, 0);
47
testDeflate(short_sample, {strategy: 3, chunkSize: 10}, 5);
48
testDeflate(long_sample, {strategy: 3, chunkSize: 10}, 0);
50
it('huffman', function() {
51
testDeflate(short_sample, {strategy: 2}, 0);
52
testDeflate(short_sample, {strategy: 2, chunkSize: 10}, 5);
53
testDeflate(long_sample, {strategy: 2, chunkSize: 10}, 0);
58
describe('Deflate states', function() {
59
//in port checking input parameters was removed
60
it('inflate bad parameters', function () {
63
ret = zlib_deflate.deflate(null, 0);
64
assert(ret === c.Z_STREAM_ERROR);
68
ret = zlib_deflate.deflateInit(null);
69
assert(ret === c.Z_STREAM_ERROR);
71
ret = zlib_deflate.deflateInit(strm, 6);
72
assert(ret === c.Z_OK);
74
ret = zlib_deflate.deflateSetHeader(null);
75
assert(ret === c.Z_STREAM_ERROR);
78
ret = zlib_deflate.deflateSetHeader(strm, null);
79
assert(ret === c.Z_STREAM_ERROR);
82
ret = zlib_deflate.deflateSetHeader(strm, null);
83
assert(ret === c.Z_OK);
85
ret = zlib_deflate.deflate(strm, c.Z_FINISH);
86
assert(ret === c.Z_BUF_ERROR);
88
ret = zlib_deflate.deflateEnd(null);
89
assert(ret === c.Z_STREAM_ERROR);
92
strm.state.status = 5;
93
ret = zlib_deflate.deflateEnd(strm);
94
assert(ret === c.Z_STREAM_ERROR);