Browse Source

zlib: tighten up dictionary tests

Uses const where possible, removes inaccurate comments, prefers
strictEqual where possible, ensures functions with assertions are called
and enures the inflater has correct encoding set.

PR-URL: https://github.com/nodejs/node/pull/8512
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
v7.x
Tarjei Husøy 8 years ago
committed by Anna Henningsen
parent
commit
2b5acda7a2
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 15
      test/parallel/test-zlib-dictionary-fail.js
  2. 30
      test/parallel/test-zlib-dictionary.js

15
test/parallel/test-zlib-dictionary-fail.js

@ -3,7 +3,9 @@ const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
// Should raise an error, not trigger an assertion in src/node_zlib.cc
// String "test" encoded with dictionary "dict".
const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]);
{
const stream = zlib.createInflate();
@ -11,11 +13,9 @@ const zlib = require('zlib');
assert(/Missing dictionary/.test(err.message));
}));
// String "test" encoded with dictionary "dict".
stream.write(Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
stream.write(input);
}
// Should raise an error, not trigger an assertion in src/node_zlib.cc
{
const stream = zlib.createInflate({ dictionary: Buffer.from('fail') });
@ -23,11 +23,9 @@ const zlib = require('zlib');
assert(/Bad dictionary/.test(err.message));
}));
// String "test" encoded with dictionary "dict".
stream.write(Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
stream.write(input);
}
// Should raise an error, not trigger an assertion in src/node_zlib.cc
{
const stream = zlib.createInflateRaw({ dictionary: Buffer.from('fail') });
@ -37,6 +35,5 @@ const zlib = require('zlib');
assert(/invalid/.test(err.message));
}));
// String "test" encoded with dictionary "dict".
stream.write(Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]));
stream.write(input);
}

30
test/parallel/test-zlib-dictionary.js

@ -1,7 +1,7 @@
'use strict';
// test compression/decompression with dictionary
require('../common');
const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
@ -32,6 +32,7 @@ function basicDictionaryTest() {
let output = '';
const deflate = zlib.createDeflate({ dictionary: spdyDict });
const inflate = zlib.createInflate({ dictionary: spdyDict });
inflate.setEncoding('utf-8');
deflate.on('data', function(chunk) {
inflate.write(chunk);
@ -45,9 +46,9 @@ function basicDictionaryTest() {
inflate.end();
});
inflate.on('end', function() {
assert.equal(input, output);
});
inflate.on('end', common.mustCall(function() {
assert.strictEqual(input, output);
}));
deflate.write(input);
deflate.end();
@ -58,6 +59,7 @@ function deflateResetDictionaryTest() {
let output = '';
const deflate = zlib.createDeflate({ dictionary: spdyDict });
const inflate = zlib.createInflate({ dictionary: spdyDict });
inflate.setEncoding('utf-8');
deflate.on('data', function(chunk) {
if (doneReset)
@ -72,9 +74,9 @@ function deflateResetDictionaryTest() {
inflate.end();
});
inflate.on('end', function() {
assert.equal(input, output);
});
inflate.on('end', common.mustCall(function() {
assert.strictEqual(input, output);
}));
deflate.write(input);
deflate.flush(function() {
@ -89,6 +91,7 @@ function rawDictionaryTest() {
let output = '';
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
const inflate = zlib.createInflateRaw({ dictionary: spdyDict });
inflate.setEncoding('utf-8');
deflate.on('data', function(chunk) {
inflate.write(chunk);
@ -102,9 +105,9 @@ function rawDictionaryTest() {
inflate.end();
});
inflate.on('end', function() {
assert.equal(input, output);
});
inflate.on('end', common.mustCall(function() {
assert.strictEqual(input, output);
}));
deflate.write(input);
deflate.end();
@ -115,6 +118,7 @@ function deflateRawResetDictionaryTest() {
let output = '';
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
const inflate = zlib.createInflateRaw({ dictionary: spdyDict });
inflate.setEncoding('utf-8');
deflate.on('data', function(chunk) {
if (doneReset)
@ -129,9 +133,9 @@ function deflateRawResetDictionaryTest() {
inflate.end();
});
inflate.on('end', function() {
assert.equal(input, output);
});
inflate.on('end', common.mustCall(function() {
assert.strictEqual(input, output);
}));
deflate.write(input);
deflate.flush(function() {

Loading…
Cancel
Save