~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to src/lib/pako/test/deflate_cover.js

  • Committer: Holger Seelig
  • Date: 2017-08-22 04:53:24 UTC
  • Revision ID: holger.seelig@yahoo.de-20170822045324-4of4xxgt79669gbt
Switched to npm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Deflate coverage tests
 
2
 
 
3
/*global describe, it*/
 
4
 
 
5
 
 
6
'use strict';
 
7
 
 
8
 
 
9
var assert = require('assert');
 
10
var fs = require('fs');
 
11
var path  = require('path');
 
12
 
 
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');
 
17
 
 
18
var pako  = require('../index');
 
19
 
 
20
 
 
21
var short_sample = 'hello world';
 
22
var long_sample = fs.readFileSync(path.join(__dirname, 'fixtures/samples/lorem_en_100k.txt'));
 
23
 
 
24
function testDeflate(data, opts, flush) {
 
25
  var deflator = new pako.Deflate(opts);
 
26
  deflator.push(data, flush);
 
27
  deflator.push(data, true);
 
28
 
 
29
  assert.equal(deflator.err, false, msg[deflator.err]);
 
30
}
 
31
 
 
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);
 
36
  });
 
37
  it('fast', function() {
 
38
    testDeflate(short_sample, {level: 1, chunkSize: 10}, 5);
 
39
    testDeflate(long_sample, {level: 1, memLevel: 1, chunkSize: 10}, 0);
 
40
  });
 
41
  it('slow', function() {
 
42
    testDeflate(short_sample, {level: 4, chunkSize: 10}, 5);
 
43
    testDeflate(long_sample, {level: 9, memLevel: 1, chunkSize: 10}, 0);
 
44
  });
 
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);
 
49
  });
 
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);
 
54
 
 
55
  });
 
56
});
 
57
 
 
58
describe('Deflate states', function() {
 
59
  //in port checking input parameters was removed
 
60
  it('inflate bad parameters', function () {
 
61
    var ret, strm;
 
62
 
 
63
    ret = zlib_deflate.deflate(null, 0);
 
64
    assert(ret === c.Z_STREAM_ERROR);
 
65
 
 
66
    strm = new zstream();
 
67
 
 
68
    ret = zlib_deflate.deflateInit(null);
 
69
    assert(ret === c.Z_STREAM_ERROR);
 
70
 
 
71
    ret = zlib_deflate.deflateInit(strm, 6);
 
72
    assert(ret === c.Z_OK);
 
73
 
 
74
    ret = zlib_deflate.deflateSetHeader(null);
 
75
    assert(ret === c.Z_STREAM_ERROR);
 
76
 
 
77
    strm.state.wrap = 1;
 
78
    ret = zlib_deflate.deflateSetHeader(strm, null);
 
79
    assert(ret === c.Z_STREAM_ERROR);
 
80
 
 
81
    strm.state.wrap = 2;
 
82
    ret = zlib_deflate.deflateSetHeader(strm, null);
 
83
    assert(ret === c.Z_OK);
 
84
 
 
85
    ret = zlib_deflate.deflate(strm, c.Z_FINISH);
 
86
    assert(ret === c.Z_BUF_ERROR);
 
87
 
 
88
    ret = zlib_deflate.deflateEnd(null);
 
89
    assert(ret === c.Z_STREAM_ERROR);
 
90
 
 
91
    //BS_NEED_MORE
 
92
    strm.state.status = 5;
 
93
    ret = zlib_deflate.deflateEnd(strm);
 
94
    assert(ret === c.Z_STREAM_ERROR);
 
95
  });
 
96
});