11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst zlib = require('zlib');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Work with and without `new` keyword
91cb0ef41Sopenharmony_ciassert.ok(zlib.Deflate() instanceof zlib.Deflate);
101cb0ef41Sopenharmony_ciassert.ok(new zlib.Deflate() instanceof zlib.Deflate);
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciassert.ok(zlib.DeflateRaw() instanceof zlib.DeflateRaw);
131cb0ef41Sopenharmony_ciassert.ok(new zlib.DeflateRaw() instanceof zlib.DeflateRaw);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// Throws if `options.chunkSize` is invalid
161cb0ef41Sopenharmony_ciassert.throws(
171cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ chunkSize: 'test' }),
181cb0ef41Sopenharmony_ci  {
191cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
201cb0ef41Sopenharmony_ci    name: 'TypeError',
211cb0ef41Sopenharmony_ci    message: 'The "options.chunkSize" property must be of type number. ' +
221cb0ef41Sopenharmony_ci             "Received type string ('test')"
231cb0ef41Sopenharmony_ci  }
241cb0ef41Sopenharmony_ci);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciassert.throws(
271cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ chunkSize: -Infinity }),
281cb0ef41Sopenharmony_ci  {
291cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
301cb0ef41Sopenharmony_ci    name: 'RangeError',
311cb0ef41Sopenharmony_ci    message: 'The value of "options.chunkSize" is out of range. It must ' +
321cb0ef41Sopenharmony_ci             'be a finite number. Received -Infinity'
331cb0ef41Sopenharmony_ci  }
341cb0ef41Sopenharmony_ci);
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciassert.throws(
371cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ chunkSize: 0 }),
381cb0ef41Sopenharmony_ci  {
391cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
401cb0ef41Sopenharmony_ci    name: 'RangeError',
411cb0ef41Sopenharmony_ci    message: 'The value of "options.chunkSize" is out of range. It must ' +
421cb0ef41Sopenharmony_ci             'be >= 64. Received 0'
431cb0ef41Sopenharmony_ci  }
441cb0ef41Sopenharmony_ci);
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci// Confirm that maximum chunk size cannot be exceeded because it is `Infinity`.
471cb0ef41Sopenharmony_ciassert.strictEqual(zlib.constants.Z_MAX_CHUNK, Infinity);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci// Throws if `options.windowBits` is invalid
501cb0ef41Sopenharmony_ciassert.throws(
511cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ windowBits: 'test' }),
521cb0ef41Sopenharmony_ci  {
531cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
541cb0ef41Sopenharmony_ci    name: 'TypeError',
551cb0ef41Sopenharmony_ci    message: 'The "options.windowBits" property must be of type number. ' +
561cb0ef41Sopenharmony_ci             "Received type string ('test')"
571cb0ef41Sopenharmony_ci  }
581cb0ef41Sopenharmony_ci);
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciassert.throws(
611cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ windowBits: -Infinity }),
621cb0ef41Sopenharmony_ci  {
631cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
641cb0ef41Sopenharmony_ci    name: 'RangeError',
651cb0ef41Sopenharmony_ci    message: 'The value of "options.windowBits" is out of range. It must ' +
661cb0ef41Sopenharmony_ci             'be a finite number. Received -Infinity'
671cb0ef41Sopenharmony_ci  }
681cb0ef41Sopenharmony_ci);
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ciassert.throws(
711cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ windowBits: Infinity }),
721cb0ef41Sopenharmony_ci  {
731cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
741cb0ef41Sopenharmony_ci    name: 'RangeError',
751cb0ef41Sopenharmony_ci    message: 'The value of "options.windowBits" is out of range. It must ' +
761cb0ef41Sopenharmony_ci             'be a finite number. Received Infinity'
771cb0ef41Sopenharmony_ci  }
781cb0ef41Sopenharmony_ci);
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ciassert.throws(
811cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ windowBits: 0 }),
821cb0ef41Sopenharmony_ci  {
831cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
841cb0ef41Sopenharmony_ci    name: 'RangeError',
851cb0ef41Sopenharmony_ci    message: 'The value of "options.windowBits" is out of range. It must ' +
861cb0ef41Sopenharmony_ci             'be >= 8 and <= 15. Received 0'
871cb0ef41Sopenharmony_ci  }
881cb0ef41Sopenharmony_ci);
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci// Throws if `options.level` is invalid
911cb0ef41Sopenharmony_ciassert.throws(
921cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ level: 'test' }),
931cb0ef41Sopenharmony_ci  {
941cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
951cb0ef41Sopenharmony_ci    name: 'TypeError',
961cb0ef41Sopenharmony_ci    message: 'The "options.level" property must be of type number. ' +
971cb0ef41Sopenharmony_ci             "Received type string ('test')"
981cb0ef41Sopenharmony_ci  }
991cb0ef41Sopenharmony_ci);
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ciassert.throws(
1021cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ level: -Infinity }),
1031cb0ef41Sopenharmony_ci  {
1041cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1051cb0ef41Sopenharmony_ci    name: 'RangeError',
1061cb0ef41Sopenharmony_ci    message: 'The value of "options.level" is out of range. It must ' +
1071cb0ef41Sopenharmony_ci             'be a finite number. Received -Infinity'
1081cb0ef41Sopenharmony_ci  }
1091cb0ef41Sopenharmony_ci);
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ciassert.throws(
1121cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ level: Infinity }),
1131cb0ef41Sopenharmony_ci  {
1141cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1151cb0ef41Sopenharmony_ci    name: 'RangeError',
1161cb0ef41Sopenharmony_ci    message: 'The value of "options.level" is out of range. It must ' +
1171cb0ef41Sopenharmony_ci             'be a finite number. Received Infinity'
1181cb0ef41Sopenharmony_ci  }
1191cb0ef41Sopenharmony_ci);
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ciassert.throws(
1221cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ level: -2 }),
1231cb0ef41Sopenharmony_ci  {
1241cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1251cb0ef41Sopenharmony_ci    name: 'RangeError',
1261cb0ef41Sopenharmony_ci    message: 'The value of "options.level" is out of range. It must ' +
1271cb0ef41Sopenharmony_ci             'be >= -1 and <= 9. Received -2'
1281cb0ef41Sopenharmony_ci  }
1291cb0ef41Sopenharmony_ci);
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci// Throws if `level` invalid in  `Deflate.prototype.params()`
1321cb0ef41Sopenharmony_ciassert.throws(
1331cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params('test'),
1341cb0ef41Sopenharmony_ci  {
1351cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
1361cb0ef41Sopenharmony_ci    name: 'TypeError',
1371cb0ef41Sopenharmony_ci    message: 'The "level" argument must be of type number. ' +
1381cb0ef41Sopenharmony_ci             "Received type string ('test')"
1391cb0ef41Sopenharmony_ci  }
1401cb0ef41Sopenharmony_ci);
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ciassert.throws(
1431cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params(-Infinity),
1441cb0ef41Sopenharmony_ci  {
1451cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1461cb0ef41Sopenharmony_ci    name: 'RangeError',
1471cb0ef41Sopenharmony_ci    message: 'The value of "level" is out of range. It must ' +
1481cb0ef41Sopenharmony_ci             'be a finite number. Received -Infinity'
1491cb0ef41Sopenharmony_ci  }
1501cb0ef41Sopenharmony_ci);
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ciassert.throws(
1531cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params(Infinity),
1541cb0ef41Sopenharmony_ci  {
1551cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1561cb0ef41Sopenharmony_ci    name: 'RangeError',
1571cb0ef41Sopenharmony_ci    message: 'The value of "level" is out of range. It must ' +
1581cb0ef41Sopenharmony_ci             'be a finite number. Received Infinity'
1591cb0ef41Sopenharmony_ci  }
1601cb0ef41Sopenharmony_ci);
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ciassert.throws(
1631cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params(-2),
1641cb0ef41Sopenharmony_ci  {
1651cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1661cb0ef41Sopenharmony_ci    name: 'RangeError',
1671cb0ef41Sopenharmony_ci    message: 'The value of "level" is out of range. It must ' +
1681cb0ef41Sopenharmony_ci             'be >= -1 and <= 9. Received -2'
1691cb0ef41Sopenharmony_ci  }
1701cb0ef41Sopenharmony_ci);
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ci// Throws if options.memLevel is invalid
1731cb0ef41Sopenharmony_ciassert.throws(
1741cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ memLevel: 'test' }),
1751cb0ef41Sopenharmony_ci  {
1761cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
1771cb0ef41Sopenharmony_ci    name: 'TypeError',
1781cb0ef41Sopenharmony_ci    message: 'The "options.memLevel" property must be of type number. ' +
1791cb0ef41Sopenharmony_ci             "Received type string ('test')"
1801cb0ef41Sopenharmony_ci  }
1811cb0ef41Sopenharmony_ci);
1821cb0ef41Sopenharmony_ci
1831cb0ef41Sopenharmony_ciassert.throws(
1841cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ memLevel: -Infinity }),
1851cb0ef41Sopenharmony_ci  {
1861cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1871cb0ef41Sopenharmony_ci    name: 'RangeError',
1881cb0ef41Sopenharmony_ci    message: 'The value of "options.memLevel" is out of range. It must ' +
1891cb0ef41Sopenharmony_ci             'be a finite number. Received -Infinity'
1901cb0ef41Sopenharmony_ci  }
1911cb0ef41Sopenharmony_ci);
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_ciassert.throws(
1941cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ memLevel: Infinity }),
1951cb0ef41Sopenharmony_ci  {
1961cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
1971cb0ef41Sopenharmony_ci    name: 'RangeError',
1981cb0ef41Sopenharmony_ci    message: 'The value of "options.memLevel" is out of range. It must ' +
1991cb0ef41Sopenharmony_ci             'be a finite number. Received Infinity'
2001cb0ef41Sopenharmony_ci  }
2011cb0ef41Sopenharmony_ci);
2021cb0ef41Sopenharmony_ci
2031cb0ef41Sopenharmony_ciassert.throws(
2041cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ memLevel: -2 }),
2051cb0ef41Sopenharmony_ci  {
2061cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
2071cb0ef41Sopenharmony_ci    name: 'RangeError',
2081cb0ef41Sopenharmony_ci    message: 'The value of "options.memLevel" is out of range. It must ' +
2091cb0ef41Sopenharmony_ci             'be >= 1 and <= 9. Received -2'
2101cb0ef41Sopenharmony_ci  }
2111cb0ef41Sopenharmony_ci);
2121cb0ef41Sopenharmony_ci
2131cb0ef41Sopenharmony_ci// Does not throw if opts.strategy is valid
2141cb0ef41Sopenharmony_cinew zlib.Deflate({ strategy: zlib.constants.Z_FILTERED });
2151cb0ef41Sopenharmony_cinew zlib.Deflate({ strategy: zlib.constants.Z_HUFFMAN_ONLY });
2161cb0ef41Sopenharmony_cinew zlib.Deflate({ strategy: zlib.constants.Z_RLE });
2171cb0ef41Sopenharmony_cinew zlib.Deflate({ strategy: zlib.constants.Z_FIXED });
2181cb0ef41Sopenharmony_cinew zlib.Deflate({ strategy: zlib.constants.Z_DEFAULT_STRATEGY });
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ci// Throws if options.strategy is invalid
2211cb0ef41Sopenharmony_ciassert.throws(
2221cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ strategy: 'test' }),
2231cb0ef41Sopenharmony_ci  {
2241cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
2251cb0ef41Sopenharmony_ci    name: 'TypeError',
2261cb0ef41Sopenharmony_ci    message: 'The "options.strategy" property must be of type number. ' +
2271cb0ef41Sopenharmony_ci             "Received type string ('test')"
2281cb0ef41Sopenharmony_ci  }
2291cb0ef41Sopenharmony_ci);
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ciassert.throws(
2321cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ strategy: -Infinity }),
2331cb0ef41Sopenharmony_ci  {
2341cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
2351cb0ef41Sopenharmony_ci    name: 'RangeError',
2361cb0ef41Sopenharmony_ci    message: 'The value of "options.strategy" is out of range. It must ' +
2371cb0ef41Sopenharmony_ci             'be a finite number. Received -Infinity'
2381cb0ef41Sopenharmony_ci  }
2391cb0ef41Sopenharmony_ci);
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ciassert.throws(
2421cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ strategy: Infinity }),
2431cb0ef41Sopenharmony_ci  {
2441cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
2451cb0ef41Sopenharmony_ci    name: 'RangeError',
2461cb0ef41Sopenharmony_ci    message: 'The value of "options.strategy" is out of range. It must ' +
2471cb0ef41Sopenharmony_ci             'be a finite number. Received Infinity'
2481cb0ef41Sopenharmony_ci  }
2491cb0ef41Sopenharmony_ci);
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ciassert.throws(
2521cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ strategy: -2 }),
2531cb0ef41Sopenharmony_ci  {
2541cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
2551cb0ef41Sopenharmony_ci    name: 'RangeError',
2561cb0ef41Sopenharmony_ci    message: 'The value of "options.strategy" is out of range. It must ' +
2571cb0ef41Sopenharmony_ci             'be >= 0 and <= 4. Received -2'
2581cb0ef41Sopenharmony_ci  }
2591cb0ef41Sopenharmony_ci);
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ci// Throws TypeError if `strategy` is invalid in `Deflate.prototype.params()`
2621cb0ef41Sopenharmony_ciassert.throws(
2631cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params(0, 'test'),
2641cb0ef41Sopenharmony_ci  {
2651cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
2661cb0ef41Sopenharmony_ci    name: 'TypeError',
2671cb0ef41Sopenharmony_ci    message: 'The "strategy" argument must be of type number. ' +
2681cb0ef41Sopenharmony_ci             "Received type string ('test')"
2691cb0ef41Sopenharmony_ci  }
2701cb0ef41Sopenharmony_ci);
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ciassert.throws(
2731cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params(0, -Infinity),
2741cb0ef41Sopenharmony_ci  {
2751cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
2761cb0ef41Sopenharmony_ci    name: 'RangeError',
2771cb0ef41Sopenharmony_ci    message: 'The value of "strategy" is out of range. It must ' +
2781cb0ef41Sopenharmony_ci             'be a finite number. Received -Infinity'
2791cb0ef41Sopenharmony_ci  }
2801cb0ef41Sopenharmony_ci);
2811cb0ef41Sopenharmony_ci
2821cb0ef41Sopenharmony_ciassert.throws(
2831cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params(0, Infinity),
2841cb0ef41Sopenharmony_ci  {
2851cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
2861cb0ef41Sopenharmony_ci    name: 'RangeError',
2871cb0ef41Sopenharmony_ci    message: 'The value of "strategy" is out of range. It must ' +
2881cb0ef41Sopenharmony_ci             'be a finite number. Received Infinity'
2891cb0ef41Sopenharmony_ci  }
2901cb0ef41Sopenharmony_ci);
2911cb0ef41Sopenharmony_ci
2921cb0ef41Sopenharmony_ciassert.throws(
2931cb0ef41Sopenharmony_ci  () => new zlib.Deflate().params(0, -2),
2941cb0ef41Sopenharmony_ci  {
2951cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
2961cb0ef41Sopenharmony_ci    name: 'RangeError',
2971cb0ef41Sopenharmony_ci    message: 'The value of "strategy" is out of range. It must ' +
2981cb0ef41Sopenharmony_ci             'be >= 0 and <= 4. Received -2'
2991cb0ef41Sopenharmony_ci  }
3001cb0ef41Sopenharmony_ci);
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci// Throws if opts.dictionary is not a Buffer
3031cb0ef41Sopenharmony_ciassert.throws(
3041cb0ef41Sopenharmony_ci  () => new zlib.Deflate({ dictionary: 'not a buffer' }),
3051cb0ef41Sopenharmony_ci  {
3061cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
3071cb0ef41Sopenharmony_ci    name: 'TypeError',
3081cb0ef41Sopenharmony_ci    message: 'The "options.dictionary" property must be an instance of Buffer' +
3091cb0ef41Sopenharmony_ci             ', TypedArray, DataView, or ArrayBuffer. Received type string ' +
3101cb0ef41Sopenharmony_ci             "('not a buffer')"
3111cb0ef41Sopenharmony_ci  }
3121cb0ef41Sopenharmony_ci);
313