com php-src: Add inflate_*() test cases: ext/zlib /tests/inflate_add_basic.phpt ext/zlib/tests/inflate_ add_error.phpt
ext/zlib/tests/inflate_init_error.ph pt ext/zlib/tests/inflate_init_reuse.phpt

From: Date: Fri, 24 Apr 2015 05:50:59 +0000
Subject: com php-src: Add inflate_*() test cases: ext/zlib /tests/inflate_add_basic.phpt ext/zlib/tests/inflate_ add_error.phpt
ext/zlib/tests/inflate_init_error.ph pt ext/zlib/tests/inflate_init_reuse.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-86462@lists.php.net to get a copy of this message
Commit: 0e6241610116ddaeb5f6be4632412ddca2296d9f Author: Daniel Lowrey <rdlowrey@php.net> Thu, 23 Apr 2015 23:10:44 -0600 Parents: 585037c1960a597a456c1cbdc210e574b3ec0e88 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0e6241610116ddaeb5f6be4632412ddca2296d9f Log: Add inflate_*() test cases Changed paths: A ext/zlib/tests/inflate_add_basic.phpt A ext/zlib/tests/inflate_add_error.phpt A ext/zlib/tests/inflate_init_error.phpt A ext/zlib/tests/inflate_init_reuse.phpt Diff: diff --git a/ext/zlib/tests/inflate_add_basic.phpt b/ext/zlib/tests/inflate_add_basic.phpt new file mode 100644 index 0000000..ff0458e --- /dev/null +++ b/ext/zlib/tests/inflate_add_basic.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test incremental inflate_add() functionality +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +function inflateStream($mode, $flushSize) { + $buffer = ""; + $inflated = null; + $resource = inflate_init($mode); + + while (true) { + $dataToInflate = yield $inflated; + if (isset($dataToInflate)) { + $buffer .= $dataToInflate; + if (strlen($buffer) >= $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 0000000..0e1711e --- /dev/null +++ b/ext/zlib/tests/inflate_add_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test incremental inflate_add() error functionality +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +$badResource = fopen("php://memory", "r+"); +var_dump(inflate_add($badResource, "test")); +$resource = inflate_init(ZLIB_ENCODING_DEFLATE); +$badFlushType = 6789; +var_dump(inflate_add($resource, "test", $badFlushType)); +?> +--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 0000000..ad1410c --- /dev/null +++ b/ext/zlib/tests/inflate_init_error.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test inflate_init() error +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +var_dump(inflate_init()); +var_dump(inflate_init(42)); +?> +--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 0000000..a6b8a30 --- /dev/null +++ b/ext/zlib/tests/inflate_init_reuse.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test incremental inflate_init() context reuse +--SKIPIF-- +<?php +if (!extension_loaded("zlib")) { + print "skip - ZLIB extension not loaded"; +} +?> +--FILE-- +<?php +$resource = inflate_init(ZLIB_ENCODING_GZIP); + +$uncompressed = implode(range("a","z")); +$compressed = gzencode($uncompressed); +$inflated = ""; +for ($i=0;$i<strlen($compressed);$i++) { + $inflated .= inflate_add($resource, $compressed[$i]); +} +$inflated .= inflate_add($resource, "", ZLIB_FINISH); +assert($inflated === $uncompressed); + +// Now reuse the existing resource after finishing the previous operations ... +$inflated = ""; +for ($i=0;$i<strlen($compressed);$i++) { + $inflated .= inflate_add($resource, $compressed[$i]); +} +$inflated .= inflate_add($resource, "", ZLIB_FINISH); +assert($inflated === $uncompressed); +?> +===DONE=== +--EXPECTF-- +===DONE===

« previous php.cvs (#86462) next »