File: 008.phpt

package info (click to toggle)
php-zstd 0.14.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,536 kB
  • sloc: ansic: 30,009; asm: 382; xml: 179; makefile: 3
file content (72 lines) | stat: -rw-r--r-- 1,614 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--TEST--
zstd_compress(): compress level
--SKIPIF--
<?php
if (LIBZSTD_VERSION_NUMBER >= 10304) die("skip needs libzstd 1.3.3 or older");
?>
--FILE--
<?php
include(dirname(__FILE__) . '/data.inc');

function check_compress($data, $level)
{
  $output = (string)zstd_compress($data, $level);
  echo $level, ' -- ', strlen($output), ' -- ',
    var_export(zstd_uncompress($output) === $data, true), PHP_EOL;
}

echo "*** Data size ***", PHP_EOL;
echo strlen($data), PHP_EOL;

echo "*** Compression Level ***", PHP_EOL;
for (
  $level = ZSTD_COMPRESS_LEVEL_MIN;
  $level <= ZSTD_COMPRESS_LEVEL_MAX;
  $level++
) {
  check_compress($data, $level);
}

echo "*** Invalid Compression Level ***", PHP_EOL;
check_compress($data, 100);
check_compress($data, -1);
?>
===Done===
--EXPECTF--
*** Data size ***
3547
*** Compression Level ***
1 -- 1%d -- true
2 -- 1%d -- true
3 -- 1%d -- true
4 -- 1%d -- true
5 -- 1%d -- true
6 -- 1%d -- true
7 -- 1%d -- true
8 -- 1%d -- true
9 -- 1%d -- true
10 -- 1%d -- true
11 -- 1%d -- true
12 -- 1%d -- true
13 -- 1%d -- true
14 -- 1%d -- true
15 -- 1%d -- true
16 -- 1%d -- true
17 -- 1%d -- true
18 -- 1%d -- true
19 -- 1%d -- true
20 -- 1%d -- true
21 -- 1%d -- true
22 -- 1%d -- true
*** Invalid Compression Level ***

Warning: zstd_compress: compression level (100) must be within 1..22 in %s on line %d
100 -- 0 -- 
Warning: zstd_uncompress: it was not compressed by zstd in %s on line %d
false

Warning: zstd_compress: compression level (-1) must be within 1..22 in %s on line %d
-1 -- 0 -- 
Warning: zstd_uncompress: it was not compressed by zstd in %s on line %d
false
===Done===