From 0e6241610116ddaeb5f6be4632412ddca2296d9f Mon Sep 17 00:00:00 2001 From: Daniel Lowrey Date: Thu, 23 Apr 2015 23:10:44 -0600 Subject: [PATCH] Add inflate_*() test cases --- ext/zlib/tests/inflate_add_basic.phpt | 73 ++++++++++++++++++++++++++ ext/zlib/tests/inflate_add_error.phpt | 23 ++++++++ ext/zlib/tests/inflate_init_error.phpt | 20 +++++++ ext/zlib/tests/inflate_init_reuse.phpt | 32 +++++++++++ 4 files changed, 148 insertions(+) create mode 100644 ext/zlib/tests/inflate_add_basic.phpt create mode 100644 ext/zlib/tests/inflate_add_error.phpt create mode 100644 ext/zlib/tests/inflate_init_error.phpt create mode 100644 ext/zlib/tests/inflate_init_reuse.phpt diff --git a/ext/zlib/tests/inflate_add_basic.phpt b/ext/zlib/tests/inflate_add_basic.phpt new file mode 100644 index 0000000000..ff0458e9ef --- /dev/null +++ b/ext/zlib/tests/inflate_add_basic.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test incremental inflate_add() functionality +--SKIPIF-- + +--FILE-- += $flushSize) { + $inflated = inflate_add($resource, $buffer); + $buffer = ""; + } else { + $inflated = null; + } + } else { + $inflated = inflate_add($resource, $buffer, ZLIB_FINISH); + } + } +} + +$modes = [ + 'ZLIB_ENCODING_RAW' => ZLIB_ENCODING_RAW, + 'ZLIB_ENCODING_GZIP' => ZLIB_ENCODING_GZIP, + 'ZLIB_ENCODING_DEFLATE' => ZLIB_ENCODING_DEFLATE, +]; +$flushSizes = [1, 4, 32768]; +$flushTypes = [ + 'ZLIB_SYNC_FLUSH' => ZLIB_SYNC_FLUSH, + 'ZLIB_PARTIAL_FLUSH' => ZLIB_PARTIAL_FLUSH, + 'ZLIB_FULL_FLUSH' => ZLIB_FULL_FLUSH, + 'ZLIB_NO_FLUSH' => ZLIB_NO_FLUSH, + 'ZLIB_BLOCK' => ZLIB_BLOCK, +]; + +$uncompressed = ""; +for ($i=0;$i<(32768*2);$i++) { + $uncompressed .= chr(rand(48,125)); +} + +foreach ($modes as $modeKey => $mode) { + $compressed = zlib_encode($uncompressed, $mode); + $compressedLen = strlen($compressed); + foreach ($flushSizes as $flushSize) { + foreach ($flushTypes as $flushTypeKey => $flushType) { + $inflated = ""; + $stream = inflateStream($mode, $flushSize, $flushType); + for ($i=0;$i<$compressedLen;$i++) { + $inflated .= $stream->send($compressed[$i]); + } + $inflated .= $stream->send(null); + if ($inflated !== $uncompressed) { + echo "Error: {$modeKey} | {$flushSize} | {$flushTypeKey}\n"; + } + } + + } +} + +?> +===DONE=== +--EXPECTF-- +===DONE=== diff --git a/ext/zlib/tests/inflate_add_error.phpt b/ext/zlib/tests/inflate_add_error.phpt new file mode 100644 index 0000000000..0e1711e0f8 --- /dev/null +++ b/ext/zlib/tests/inflate_add_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test incremental inflate_add() error functionality +--SKIPIF-- + +--FILE-- + +--EXPECTF-- + +Warning: inflate_add(): Invalid zlib.inflate resource in %s on line %d +bool(false) + +Warning: inflate_add(): flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH in %s on line %d +bool(false) diff --git a/ext/zlib/tests/inflate_init_error.phpt b/ext/zlib/tests/inflate_init_error.phpt new file mode 100644 index 0000000000..ad1410cab4 --- /dev/null +++ b/ext/zlib/tests/inflate_init_error.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test inflate_init() error +--SKIPIF-- + +--FILE-- + +--EXPECTF-- + +Warning: inflate_init() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: inflate_init(): encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d +bool(false) diff --git a/ext/zlib/tests/inflate_init_reuse.phpt b/ext/zlib/tests/inflate_init_reuse.phpt new file mode 100644 index 0000000000..a6b8a309c0 --- /dev/null +++ b/ext/zlib/tests/inflate_init_reuse.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test incremental inflate_init() context reuse +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECTF-- +===DONE=== -- 2.40.0