summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2017-03-22 19:45:03 -0700
committerAnna Henningsen <anna@addaleax.net>2017-04-03 09:50:09 +0200
commit91383e47fdbb87ae45365396dd0150dcad8ed967 (patch)
treeb68f4883bf29d10bf78aa097fd3c3c8ca736d855 /test
parent2d039ffa29e4c4366a1028555b71cb36b7129fb1 (diff)
downloadandroid-node-v8-91383e47fdbb87ae45365396dd0150dcad8ed967.tar.gz
android-node-v8-91383e47fdbb87ae45365396dd0150dcad8ed967.tar.bz2
android-node-v8-91383e47fdbb87ae45365396dd0150dcad8ed967.zip
zlib: support Uint8Array in convenience methods
Also support Uint8Array as a `dictionary` option. PR-URL: https://github.com/nodejs/node/pull/12001 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-zlib-convenience-methods.js81
-rw-r--r--test/parallel/test-zlib-deflate-constructors.js2
-rw-r--r--test/parallel/test-zlib-dictionary.js19
-rw-r--r--test/parallel/test-zlib-not-string-or-buffer.js3
4 files changed, 55 insertions, 50 deletions
diff --git a/test/parallel/test-zlib-convenience-methods.js b/test/parallel/test-zlib-convenience-methods.js
index 5f1e1ce9e2..df56f21ff4 100644
--- a/test/parallel/test-zlib-convenience-methods.js
+++ b/test/parallel/test-zlib-convenience-methods.js
@@ -22,59 +22,60 @@
'use strict';
// test convenience methods with and without options supplied
-require('../common');
+const common = require('../common');
const assert = require('assert');
const zlib = require('zlib');
-let hadRun = 0;
-
-const expect = 'blahblahblahblahblahblah';
+const expectStr = 'blahblahblahblahblahblah';
+const expectBuf = Buffer.from(expectStr);
+const expectUint8Array = new Uint8Array(expectBuf);
const opts = {
level: 9,
chunkSize: 1024,
};
-[
+for (const method of [
['gzip', 'gunzip'],
['gzip', 'unzip'],
['deflate', 'inflate'],
['deflateRaw', 'inflateRaw'],
-].forEach(function(method) {
-
- zlib[method[0]](expect, opts, function(err, result) {
- zlib[method[1]](result, opts, function(err, result) {
- assert.strictEqual(result.toString(), expect,
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' with options.');
- hadRun++;
- });
- });
-
- zlib[method[0]](expect, function(err, result) {
- zlib[method[1]](result, function(err, result) {
- assert.strictEqual(result.toString(), expect,
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' without options.');
- hadRun++;
- });
- });
+]) {
+ for (const [type, expect] of [
+ ['string', expectStr],
+ ['Buffer', expectBuf],
+ ['Uint8Array', expectUint8Array]
+ ]) {
+ zlib[method[0]](expect, opts, common.mustCall((err, result) => {
+ zlib[method[1]](result, opts, common.mustCall((err, result) => {
+ assert.strictEqual(result.toString(), expectStr,
+ `Should get original string after ${method[0]}/` +
+ `${method[1]} ${type} with options.`);
+ }));
+ }));
- let result = zlib[method[0] + 'Sync'](expect, opts);
- result = zlib[method[1] + 'Sync'](result, opts);
- assert.strictEqual(result.toString(), expect,
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' with options.');
- hadRun++;
+ zlib[method[0]](expect, common.mustCall((err, result) => {
+ zlib[method[1]](result, common.mustCall((err, result) => {
+ assert.strictEqual(result.toString(), expectStr,
+ `Should get original string after ${method[0]}/` +
+ `${method[1]} ${type} without options.`);
+ }));
+ }));
- result = zlib[method[0] + 'Sync'](expect);
- result = zlib[method[1] + 'Sync'](result);
- assert.strictEqual(result.toString(), expect,
- 'Should get original string after ' +
- method[0] + '/' + method[1] + ' without options.');
- hadRun++;
+ {
+ const compressed = zlib[method[0] + 'Sync'](expect, opts);
+ const decompressed = zlib[method[1] + 'Sync'](compressed, opts);
+ assert.strictEqual(decompressed.toString(), expectStr,
+ `Should get original string after ${method[0]}Sync/` +
+ `${method[1]}Sync ${type} with options.`);
+ }
-});
-process.on('exit', function() {
- assert.strictEqual(hadRun, 16, 'expect 16 compressions');
-});
+ {
+ const compressed = zlib[method[0] + 'Sync'](expect);
+ const decompressed = zlib[method[1] + 'Sync'](compressed);
+ assert.strictEqual(decompressed.toString(), expectStr,
+ `Should get original string after ${method[0]}Sync/` +
+ `${method[1]}Sync ${type} without options.`);
+ }
+ }
+}
diff --git a/test/parallel/test-zlib-deflate-constructors.js b/test/parallel/test-zlib-deflate-constructors.js
index ca9c4f801b..c495d2d11d 100644
--- a/test/parallel/test-zlib-deflate-constructors.js
+++ b/test/parallel/test-zlib-deflate-constructors.js
@@ -107,5 +107,5 @@ assert.throws(
// Throws if opts.dictionary is not a Buffer
assert.throws(
() => { new zlib.Deflate({dictionary: 'not a buffer'}); },
- /^TypeError: Invalid dictionary: it should be a Buffer instance$/
+ /^TypeError: Invalid dictionary: it should be a Buffer or an Uint8Array$/
);
diff --git a/test/parallel/test-zlib-dictionary.js b/test/parallel/test-zlib-dictionary.js
index fd70d73556..a3b55bc72d 100644
--- a/test/parallel/test-zlib-dictionary.js
+++ b/test/parallel/test-zlib-dictionary.js
@@ -41,6 +41,7 @@ const spdyDict = Buffer.from([
'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1',
'.1statusversionurl\0'
].join(''));
+const spdyDictUint8Array = new Uint8Array(spdyDict);
const input = [
'HTTP/1.1 200 Ok',
@@ -49,7 +50,7 @@ const input = [
''
].join('\r\n');
-function basicDictionaryTest() {
+function basicDictionaryTest(spdyDict) {
let output = '';
const deflate = zlib.createDeflate({ dictionary: spdyDict });
const inflate = zlib.createInflate({ dictionary: spdyDict });
@@ -75,7 +76,7 @@ function basicDictionaryTest() {
deflate.end();
}
-function deflateResetDictionaryTest() {
+function deflateResetDictionaryTest(spdyDict) {
let doneReset = false;
let output = '';
const deflate = zlib.createDeflate({ dictionary: spdyDict });
@@ -108,7 +109,7 @@ function deflateResetDictionaryTest() {
});
}
-function rawDictionaryTest() {
+function rawDictionaryTest(spdyDict) {
let output = '';
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
const inflate = zlib.createInflateRaw({ dictionary: spdyDict });
@@ -134,7 +135,7 @@ function rawDictionaryTest() {
deflate.end();
}
-function deflateRawResetDictionaryTest() {
+function deflateRawResetDictionaryTest(spdyDict) {
let doneReset = false;
let output = '';
const deflate = zlib.createDeflateRaw({ dictionary: spdyDict });
@@ -167,7 +168,9 @@ function deflateRawResetDictionaryTest() {
});
}
-basicDictionaryTest();
-deflateResetDictionaryTest();
-rawDictionaryTest();
-deflateRawResetDictionaryTest();
+for (const dict of [spdyDict, spdyDictUint8Array]) {
+ basicDictionaryTest(dict);
+ deflateResetDictionaryTest(dict);
+ rawDictionaryTest(dict);
+ deflateRawResetDictionaryTest(dict);
+}
diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js
index 3f58583e03..510e111f70 100644
--- a/test/parallel/test-zlib-not-string-or-buffer.js
+++ b/test/parallel/test-zlib-not-string-or-buffer.js
@@ -7,7 +7,8 @@ require('../common');
const assert = require('assert');
const zlib = require('zlib');
-const expected = /^TypeError: Not a string or buffer$/;
+const expected =
+ /^TypeError: "buffer" argument must be a string, Buffer, or Uint8Array$/;
assert.throws(() => { zlib.deflateSync(undefined); }, expected);
assert.throws(() => { zlib.deflateSync(null); }, expected);