Permalink
Browse files

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: #8512
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
thusoy authored and Fishrock123 committed Sep 14, 2016
1 parent 1547495 commit 7403aaa13f9de6cbc1f702515f0447bc5a7193af
Showing with 23 additions and 22 deletions.
  1. +6 −9 test/parallel/test-zlib-dictionary-fail.js
  2. +17 −13 test/parallel/test-zlib-dictionary.js
@@ -3,31 +3,29 @@ 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();
stream.on('error', common.mustCall(function(err) {
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') });
stream.on('error', common.mustCall(function(err) {
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);
}
@@ -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() {

0 comments on commit 7403aaa

Please sign in to comment.