Skip to content

Commit

Permalink
test: add brotli_compress_add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kjdev committed Jan 19, 2024
1 parent 01cc55d commit 4c6f6d7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/compress_add.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Test brotli_compress_add() functionality
--SKIPIF--
<?php
if (!extension_loaded('brotli')) die('skip need ext/brotli');
if (PHP_VERSION_ID < 70000) die('skip need version: 7.0+');
?>
--FILE--
<?php

$brotliContext = brotli_compress_init();

$strings = [
'Hello, how are you? How is it going?' . PHP_EOL,
'I am fine thanks' . PHP_EOL,
'Hello, how are you? How is it going?' . PHP_EOL,
];

$compressed = '';
foreach ($strings as $string) {
$compressedString = brotli_compress_add($brotliContext, $string);
if (strlen($compressedString) === 0) {
echo "Incremental compress failed\n";
} elseif ($compressedString === $string) {
// temporary only for test
echo "Incremental compress failed to compress\n";
} else {
$compressed .= $compressedString;
}
}

$compressed .= brotli_compress_add($brotliContext, '', BROTLI_FINISH);
if (brotli_uncompress($compressed) !== implode('', $strings)) {
echo "Compression invalid\n";
} else {
echo "OK\n";
}
?>
===DONE===
--EXPECTF--
OK
===DONE===

0 comments on commit 4c6f6d7

Please sign in to comment.