test: improve multiple zlib tests
PR-URL: https://github.com/nodejs/node/pull/14455 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
4b23b42981
commit
4e8bc7181c
@ -38,9 +38,11 @@ assert.throws(
|
|||||||
);
|
);
|
||||||
|
|
||||||
zlib.gunzip(data, common.mustCall((err, result) => {
|
zlib.gunzip(data, common.mustCall((err, result) => {
|
||||||
assert(err instanceof Error);
|
common.expectsError({
|
||||||
assert.strictEqual(err.code, 'Z_DATA_ERROR');
|
code: 'Z_DATA_ERROR',
|
||||||
assert.strictEqual(err.message, 'unknown compression method');
|
type: Error,
|
||||||
|
message: 'unknown compression method'
|
||||||
|
})(err);
|
||||||
assert.strictEqual(result, undefined);
|
assert.strictEqual(result, undefined);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -42,10 +42,10 @@ const inp = fs.createReadStream(fixture);
|
|||||||
const out = fs.createWriteStream(outputFile);
|
const out = fs.createWriteStream(outputFile);
|
||||||
|
|
||||||
inp.pipe(gunzip).pipe(out);
|
inp.pipe(gunzip).pipe(out);
|
||||||
out.on('close', function() {
|
out.on('close', common.mustCall(() => {
|
||||||
const actual = fs.readFileSync(outputFile);
|
const actual = fs.readFileSync(outputFile);
|
||||||
assert.strictEqual(actual.length, expect.length, 'length should match');
|
assert.strictEqual(actual.length, expect.length, 'length should match');
|
||||||
for (let i = 0, l = actual.length; i < l; i++) {
|
for (let i = 0, l = actual.length; i < l; i++) {
|
||||||
assert.strictEqual(actual[i], expect[i], `byte[${i}]`);
|
assert.strictEqual(actual[i], expect[i], `byte[${i}]`);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
// test compressing and uncompressing a string with zlib
|
// test compressing and uncompressing a string with zlib
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
@ -54,32 +54,32 @@ const expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN4' +
|
|||||||
'mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2' +
|
'mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2' +
|
||||||
'sHnHNzRtagj5AQAA';
|
'sHnHNzRtagj5AQAA';
|
||||||
|
|
||||||
zlib.deflate(inputString, function(err, buffer) {
|
zlib.deflate(inputString, common.mustCall((err, buffer) => {
|
||||||
assert.strictEqual(buffer.toString('base64'), expectedBase64Deflate,
|
assert.strictEqual(buffer.toString('base64'), expectedBase64Deflate,
|
||||||
'deflate encoded string should match');
|
'deflate encoded string should match');
|
||||||
});
|
}));
|
||||||
|
|
||||||
zlib.gzip(inputString, function(err, buffer) {
|
zlib.gzip(inputString, common.mustCall((err, buffer) => {
|
||||||
// Can't actually guarantee that we'll get exactly the same
|
// Can't actually guarantee that we'll get exactly the same
|
||||||
// deflated bytes when we compress a string, since the header
|
// deflated bytes when we compress a string, since the header
|
||||||
// depends on stuff other than the input string itself.
|
// depends on stuff other than the input string itself.
|
||||||
// However, decrypting it should definitely yield the same
|
// However, decrypting it should definitely yield the same
|
||||||
// result that we're expecting, and this should match what we get
|
// result that we're expecting, and this should match what we get
|
||||||
// from inflating the known valid deflate data.
|
// from inflating the known valid deflate data.
|
||||||
zlib.gunzip(buffer, function(err, gunzipped) {
|
zlib.gunzip(buffer, common.mustCall((err, gunzipped) => {
|
||||||
assert.strictEqual(gunzipped.toString(), inputString,
|
assert.strictEqual(gunzipped.toString(), inputString,
|
||||||
'Should get original string after gzip/gunzip');
|
'Should get original string after gzip/gunzip');
|
||||||
});
|
}));
|
||||||
});
|
}));
|
||||||
|
|
||||||
let buffer = Buffer.from(expectedBase64Deflate, 'base64');
|
let buffer = Buffer.from(expectedBase64Deflate, 'base64');
|
||||||
zlib.unzip(buffer, function(err, buffer) {
|
zlib.unzip(buffer, common.mustCall((err, buffer) => {
|
||||||
assert.strictEqual(buffer.toString(), inputString,
|
assert.strictEqual(buffer.toString(), inputString,
|
||||||
'decoded inflated string should match');
|
'decoded inflated string should match');
|
||||||
});
|
}));
|
||||||
|
|
||||||
buffer = Buffer.from(expectedBase64Gzip, 'base64');
|
buffer = Buffer.from(expectedBase64Gzip, 'base64');
|
||||||
zlib.unzip(buffer, function(err, buffer) {
|
zlib.unzip(buffer, common.mustCall((err, buffer) => {
|
||||||
assert.strictEqual(buffer.toString(), inputString,
|
assert.strictEqual(buffer.toString(), inputString,
|
||||||
'decoded gunzipped string should match');
|
'decoded gunzipped string should match');
|
||||||
});
|
}));
|
||||||
|
@ -22,14 +22,26 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
// test uncompressing invalid input
|
// test uncompressing invalid input
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
const nonStringInputs = [1, true, { a: 1 }, ['a']];
|
const nonStringInputs = [
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
{ a: 1 },
|
||||||
|
['a']
|
||||||
|
];
|
||||||
|
|
||||||
console.error('Doing the non-strings');
|
// zlib.Unzip classes need to get valid data, or else they'll throw.
|
||||||
nonStringInputs.forEach(function(input) {
|
const unzips = [
|
||||||
|
zlib.Unzip(),
|
||||||
|
zlib.Gunzip(),
|
||||||
|
zlib.Inflate(),
|
||||||
|
zlib.InflateRaw()
|
||||||
|
];
|
||||||
|
|
||||||
|
nonStringInputs.forEach(common.mustCall((input) => {
|
||||||
// zlib.gunzip should not throw an error when called with bad input.
|
// zlib.gunzip should not throw an error when called with bad input.
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
zlib.gunzip(input, function(err, buffer) {
|
zlib.gunzip(input, function(err, buffer) {
|
||||||
@ -37,30 +49,12 @@ nonStringInputs.forEach(function(input) {
|
|||||||
assert.ok(err);
|
assert.ok(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}, nonStringInputs.length));
|
||||||
|
|
||||||
console.error('Doing the unzips');
|
unzips.forEach(common.mustCall((uz, i) => {
|
||||||
// zlib.Unzip classes need to get valid data, or else they'll throw.
|
uz.on('error', common.mustCall());
|
||||||
const unzips = [ zlib.Unzip(),
|
uz.on('end', common.mustNotCall);
|
||||||
zlib.Gunzip(),
|
|
||||||
zlib.Inflate(),
|
|
||||||
zlib.InflateRaw() ];
|
|
||||||
const hadError = [];
|
|
||||||
unzips.forEach(function(uz, i) {
|
|
||||||
console.error(`Error for ${uz.constructor.name}`);
|
|
||||||
uz.on('error', function(er) {
|
|
||||||
console.error('Error event', er);
|
|
||||||
hadError[i] = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
uz.on('end', function(er) {
|
|
||||||
throw new Error(`end event should not be emitted ${uz.constructor.name}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// this will trigger error event
|
// this will trigger error event
|
||||||
uz.write('this is not valid compressed data.');
|
uz.write('this is not valid compressed data.');
|
||||||
});
|
}, unzips.length));
|
||||||
|
|
||||||
process.on('exit', function() {
|
|
||||||
assert.deepStrictEqual(hadError, [true, true, true, true], 'expect 4 errors');
|
|
||||||
});
|
|
||||||
|
@ -27,14 +27,14 @@ if (!common.hasCrypto)
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const util = require('util');
|
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
const Stream = stream.Stream;
|
const Stream = stream.Stream;
|
||||||
|
|
||||||
// emit random bytes, and keep a shasum
|
// emit random bytes, and keep a shasum
|
||||||
function RandomReadStream(opt) {
|
class RandomReadStream extends Stream {
|
||||||
Stream.call(this);
|
constructor(opt) {
|
||||||
|
super();
|
||||||
|
|
||||||
this.readable = true;
|
this.readable = true;
|
||||||
this._paused = false;
|
this._paused = false;
|
||||||
@ -58,23 +58,21 @@ function RandomReadStream(opt) {
|
|||||||
this._process = this._process.bind(this);
|
this._process = this._process.bind(this);
|
||||||
|
|
||||||
process.nextTick(this._process);
|
process.nextTick(this._process);
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(RandomReadStream, Stream);
|
pause() {
|
||||||
|
|
||||||
RandomReadStream.prototype.pause = function() {
|
|
||||||
this._paused = true;
|
this._paused = true;
|
||||||
this.emit('pause');
|
this.emit('pause');
|
||||||
};
|
}
|
||||||
|
|
||||||
RandomReadStream.prototype.resume = function() {
|
resume() {
|
||||||
// console.error("rrs resume");
|
// console.error("rrs resume");
|
||||||
this._paused = false;
|
this._paused = false;
|
||||||
this.emit('resume');
|
this.emit('resume');
|
||||||
this._process();
|
this._process();
|
||||||
};
|
}
|
||||||
|
|
||||||
RandomReadStream.prototype._process = function() {
|
_process() {
|
||||||
if (this._processing) return;
|
if (this._processing) return;
|
||||||
if (this._paused) return;
|
if (this._paused) return;
|
||||||
|
|
||||||
@ -105,46 +103,43 @@ RandomReadStream.prototype._process = function() {
|
|||||||
|
|
||||||
this._remaining -= block;
|
this._remaining -= block;
|
||||||
|
|
||||||
console.error('block=%d\nremain=%d\n', block, this._remaining);
|
|
||||||
this._processing = false;
|
this._processing = false;
|
||||||
|
|
||||||
this.emit('data', buf);
|
this.emit('data', buf);
|
||||||
process.nextTick(this._process);
|
process.nextTick(this._process);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// a filter that just verifies a shasum
|
|
||||||
function HashStream() {
|
|
||||||
Stream.call(this);
|
|
||||||
|
|
||||||
this.readable = this.writable = true;
|
|
||||||
this._hasher = crypto.createHash('sha1');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(HashStream, Stream);
|
// a filter that just verifies a shasum
|
||||||
|
class HashStream extends Stream {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.readable = this.writable = true;
|
||||||
|
this._hasher = crypto.createHash('sha1');
|
||||||
|
}
|
||||||
|
|
||||||
HashStream.prototype.write = function(c) {
|
write(c) {
|
||||||
// Simulate the way that an fs.ReadStream returns false
|
// Simulate the way that an fs.ReadStream returns false
|
||||||
// on *every* write like a jerk, only to resume a
|
// on *every* write, only to resume a moment later.
|
||||||
// moment later.
|
|
||||||
this._hasher.update(c);
|
this._hasher.update(c);
|
||||||
process.nextTick(this.resume.bind(this));
|
process.nextTick(() => this.resume());
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
HashStream.prototype.resume = function() {
|
resume() {
|
||||||
this.emit('resume');
|
this.emit('resume');
|
||||||
process.nextTick(this.emit.bind(this, 'drain'));
|
process.nextTick(() => this.emit('drain'));
|
||||||
};
|
}
|
||||||
|
|
||||||
HashStream.prototype.end = function(c) {
|
end(c) {
|
||||||
if (c) {
|
if (c) {
|
||||||
this.write(c);
|
this.write(c);
|
||||||
}
|
}
|
||||||
this._hash = this._hasher.digest('hex').toLowerCase().trim();
|
this._hash = this._hasher.digest('hex').toLowerCase().trim();
|
||||||
this.emit('data', this._hash);
|
this.emit('data', this._hash);
|
||||||
this.emit('end');
|
this.emit('end');
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 });
|
const inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 });
|
||||||
@ -154,23 +149,6 @@ const gunz = zlib.createGunzip();
|
|||||||
|
|
||||||
inp.pipe(gzip).pipe(gunz).pipe(out);
|
inp.pipe(gzip).pipe(gunz).pipe(out);
|
||||||
|
|
||||||
inp.on('data', function(c) {
|
out.on('data', common.mustCall((c) => {
|
||||||
console.error('inp data', c.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
gzip.on('data', function(c) {
|
|
||||||
console.error('gzip data', c.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
gunz.on('data', function(c) {
|
|
||||||
console.error('gunz data', c.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
out.on('data', function(c) {
|
|
||||||
console.error('out data', c.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
out.on('data', common.mustCall(function(c) {
|
|
||||||
console.error('hash=%s', c);
|
|
||||||
assert.strictEqual(c, inp._hash, 'hashes should match');
|
assert.strictEqual(c, inp._hash, 'hashes should match');
|
||||||
}));
|
}));
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const shouldNotBeCalled = () => { throw new Error('unexpected event'); };
|
|
||||||
|
|
||||||
const message = 'Come on, Fhqwhgads.';
|
const message = 'Come on, Fhqwhgads.';
|
||||||
|
const buffer = Buffer.from(message);
|
||||||
|
|
||||||
const zipper = new zlib.Gzip();
|
const zipper = new zlib.Gzip();
|
||||||
zipper.on('close', shouldNotBeCalled);
|
zipper.on('close', common.mustNotCall);
|
||||||
|
|
||||||
const buffer = Buffer.from(message);
|
|
||||||
const zipped = zipper._processChunk(buffer, zlib.constants.Z_FINISH);
|
const zipped = zipper._processChunk(buffer, zlib.constants.Z_FINISH);
|
||||||
|
|
||||||
const unzipper = new zlib.Gunzip();
|
const unzipper = new zlib.Gunzip();
|
||||||
unzipper.on('close', shouldNotBeCalled);
|
unzipper.on('close', common.mustNotCall);
|
||||||
|
|
||||||
const unzipped = unzipper._processChunk(zipped, zlib.constants.Z_FINISH);
|
const unzipped = unzipper._processChunk(zipped, zlib.constants.Z_FINISH);
|
||||||
assert.notStrictEqual(zipped.toString(), message);
|
assert.notStrictEqual(zipped.toString(), message);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
|
|
||||||
@ -32,23 +32,14 @@ gzip.pipe(gunz);
|
|||||||
let output = '';
|
let output = '';
|
||||||
const input = 'A line of data\n';
|
const input = 'A line of data\n';
|
||||||
gunz.setEncoding('utf8');
|
gunz.setEncoding('utf8');
|
||||||
gunz.on('data', function(c) {
|
gunz.on('data', (c) => output += c);
|
||||||
output += c;
|
gunz.on('end', common.mustCall(() => {
|
||||||
});
|
|
||||||
|
|
||||||
process.on('exit', function() {
|
|
||||||
assert.strictEqual(output, input);
|
assert.strictEqual(output, input);
|
||||||
|
|
||||||
// Make sure that the flush flag was set back to normal
|
|
||||||
assert.strictEqual(gzip._flushFlag, zlib.constants.Z_NO_FLUSH);
|
assert.strictEqual(gzip._flushFlag, zlib.constants.Z_NO_FLUSH);
|
||||||
|
}));
|
||||||
console.log('ok');
|
|
||||||
});
|
|
||||||
|
|
||||||
// make sure that flush/write doesn't trigger an assert failure
|
// make sure that flush/write doesn't trigger an assert failure
|
||||||
gzip.flush(); write();
|
gzip.flush();
|
||||||
function write() {
|
gzip.write(input);
|
||||||
gzip.write(input);
|
gzip.end();
|
||||||
gzip.end();
|
gunz.read(0);
|
||||||
gunz.read(0);
|
|
||||||
}
|
|
||||||
|
@ -25,7 +25,6 @@ const assert = require('assert');
|
|||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const util = require('util');
|
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
|
|
||||||
let zlibPairs = [
|
let zlibPairs = [
|
||||||
@ -69,60 +68,60 @@ if (process.env.FAST) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tests = {};
|
const tests = {};
|
||||||
testFiles.forEach(function(file) {
|
testFiles.forEach(common.mustCall((file) => {
|
||||||
tests[file] = fs.readFileSync(path.resolve(common.fixturesDir, file));
|
tests[file] = fs.readFileSync(path.resolve(common.fixturesDir, file));
|
||||||
});
|
}, testFiles.length));
|
||||||
|
|
||||||
|
|
||||||
// stream that saves everything
|
// stream that saves everything
|
||||||
function BufferStream() {
|
class BufferStream extends stream.Stream {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
this.chunks = [];
|
this.chunks = [];
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
this.writable = true;
|
this.writable = true;
|
||||||
this.readable = true;
|
this.readable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(BufferStream, stream.Stream);
|
write(c) {
|
||||||
|
|
||||||
BufferStream.prototype.write = function(c) {
|
|
||||||
this.chunks.push(c);
|
this.chunks.push(c);
|
||||||
this.length += c.length;
|
this.length += c.length;
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
BufferStream.prototype.end = function(c) {
|
end(c) {
|
||||||
if (c) this.write(c);
|
if (c) this.write(c);
|
||||||
// flatten
|
// flatten
|
||||||
const buf = Buffer.allocUnsafe(this.length);
|
const buf = Buffer.allocUnsafe(this.length);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
this.chunks.forEach(function(c) {
|
this.chunks.forEach((c) => {
|
||||||
c.copy(buf, i);
|
c.copy(buf, i);
|
||||||
i += c.length;
|
i += c.length;
|
||||||
});
|
});
|
||||||
this.emit('data', buf);
|
this.emit('data', buf);
|
||||||
this.emit('end');
|
this.emit('end');
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SlowStream extends stream.Stream {
|
||||||
function SlowStream(trickle) {
|
constructor(trickle) {
|
||||||
|
super();
|
||||||
this.trickle = trickle;
|
this.trickle = trickle;
|
||||||
this.offset = 0;
|
this.offset = 0;
|
||||||
this.readable = this.writable = true;
|
this.readable = this.writable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(SlowStream, stream.Stream);
|
write() {
|
||||||
|
|
||||||
SlowStream.prototype.write = function() {
|
|
||||||
throw new Error('not implemented, just call ss.end(chunk)');
|
throw new Error('not implemented, just call ss.end(chunk)');
|
||||||
};
|
}
|
||||||
|
|
||||||
SlowStream.prototype.pause = function() {
|
pause() {
|
||||||
this.paused = true;
|
this.paused = true;
|
||||||
this.emit('pause');
|
this.emit('pause');
|
||||||
};
|
}
|
||||||
|
|
||||||
SlowStream.prototype.resume = function() {
|
resume() {
|
||||||
const emit = () => {
|
const emit = () => {
|
||||||
if (this.paused) return;
|
if (this.paused) return;
|
||||||
if (this.offset >= this.length) {
|
if (this.offset >= this.length) {
|
||||||
@ -141,33 +140,32 @@ SlowStream.prototype.resume = function() {
|
|||||||
if (!this.chunk) return;
|
if (!this.chunk) return;
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
emit();
|
emit();
|
||||||
};
|
}
|
||||||
|
|
||||||
SlowStream.prototype.end = function(chunk) {
|
end(chunk) {
|
||||||
// walk over the chunk in blocks.
|
// walk over the chunk in blocks.
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
this.length = chunk.length;
|
this.length = chunk.length;
|
||||||
this.resume();
|
this.resume();
|
||||||
return this.ended;
|
return this.ended;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// for each of the files, make sure that compressing and
|
// for each of the files, make sure that compressing and
|
||||||
// decompressing results in the same data, for every combination
|
// decompressing results in the same data, for every combination
|
||||||
// of the options set above.
|
// of the options set above.
|
||||||
let failures = 0;
|
|
||||||
let total = 0;
|
|
||||||
let done = 0;
|
|
||||||
|
|
||||||
Object.keys(tests).forEach(function(file) {
|
const testKeys = Object.keys(tests);
|
||||||
|
testKeys.forEach(common.mustCall((file) => {
|
||||||
const test = tests[file];
|
const test = tests[file];
|
||||||
chunkSize.forEach(function(chunkSize) {
|
chunkSize.forEach(common.mustCall((chunkSize) => {
|
||||||
trickle.forEach(function(trickle) {
|
trickle.forEach(common.mustCall((trickle) => {
|
||||||
windowBits.forEach(function(windowBits) {
|
windowBits.forEach(common.mustCall((windowBits) => {
|
||||||
level.forEach(function(level) {
|
level.forEach(common.mustCall((level) => {
|
||||||
memLevel.forEach(function(memLevel) {
|
memLevel.forEach(common.mustCall((memLevel) => {
|
||||||
strategy.forEach(function(strategy) {
|
strategy.forEach(common.mustCall((strategy) => {
|
||||||
zlibPairs.forEach(function(pair) {
|
zlibPairs.forEach(common.mustCall((pair) => {
|
||||||
const Def = pair[0];
|
const Def = pair[0];
|
||||||
const Inf = pair[1];
|
const Inf = pair[1];
|
||||||
const opts = { level: level,
|
const opts = { level: level,
|
||||||
@ -175,57 +173,32 @@ Object.keys(tests).forEach(function(file) {
|
|||||||
memLevel: memLevel,
|
memLevel: memLevel,
|
||||||
strategy: strategy };
|
strategy: strategy };
|
||||||
|
|
||||||
total++;
|
|
||||||
|
|
||||||
const def = new Def(opts);
|
const def = new Def(opts);
|
||||||
const inf = new Inf(opts);
|
const inf = new Inf(opts);
|
||||||
const ss = new SlowStream(trickle);
|
const ss = new SlowStream(trickle);
|
||||||
const buf = new BufferStream();
|
const buf = new BufferStream();
|
||||||
|
|
||||||
// verify that the same exact buffer comes out the other end.
|
// verify that the same exact buffer comes out the other end.
|
||||||
buf.on('data', function(c) {
|
buf.on('data', common.mustCall((c) => {
|
||||||
const msg = `${file} ${chunkSize} ${
|
const msg = `${file} ${chunkSize} ${
|
||||||
JSON.stringify(opts)} ${Def.name} -> ${Inf.name}`;
|
JSON.stringify(opts)} ${Def.name} -> ${Inf.name}`;
|
||||||
let ok = true;
|
|
||||||
const testNum = ++done;
|
|
||||||
let i;
|
let i;
|
||||||
for (i = 0; i < Math.max(c.length, test.length); i++) {
|
for (i = 0; i < Math.max(c.length, test.length); i++) {
|
||||||
if (c[i] !== test[i]) {
|
if (c[i] !== test[i]) {
|
||||||
ok = false;
|
assert.fail(msg);
|
||||||
failures++;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ok) {
|
}));
|
||||||
console.log(`ok ${testNum} ${msg}`);
|
|
||||||
} else {
|
|
||||||
console.log(`not ok ${testNum} msg`);
|
|
||||||
console.log(' ...');
|
|
||||||
console.log(` testfile: ${file}`);
|
|
||||||
console.log(` type: ${Def.name} -> ${Inf.name}`);
|
|
||||||
console.log(` position: ${i}`);
|
|
||||||
console.log(` options: ${JSON.stringify(opts)}`);
|
|
||||||
console.log(` expect: ${test[i]}`);
|
|
||||||
console.log(` actual: ${c[i]}`);
|
|
||||||
console.log(` chunkSize: ${chunkSize}`);
|
|
||||||
console.log(' ---');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// the magic happens here.
|
// the magic happens here.
|
||||||
ss.pipe(def).pipe(inf).pipe(buf);
|
ss.pipe(def).pipe(inf).pipe(buf);
|
||||||
ss.end(test);
|
ss.end(test);
|
||||||
});
|
}, zlibPairs.length));
|
||||||
});
|
}, strategy.length));
|
||||||
});
|
}, memLevel.length));
|
||||||
});
|
}, level.length));
|
||||||
});
|
}, windowBits.length));
|
||||||
});
|
}, trickle.length));
|
||||||
});
|
}, chunkSize.length));
|
||||||
});
|
}, testKeys.length));
|
||||||
|
|
||||||
process.on('exit', function(code) {
|
|
||||||
console.log(`1..${done}`);
|
|
||||||
assert.strictEqual(done, total, `${total - done} tests left unfinished`);
|
|
||||||
assert.strictEqual(failures, 0, 'some test failures');
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user