1--TEST--
2Test dictionary usage on zlib methods
3--SKIPIF--
4<?php if(!extension_loaded('zlib')) die('skip zlib extension not loaded'); ?>
5--FILE--
6<?php
7
8$dict = range("a", "z");
9
10$r = deflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => $dict]);
11$a = deflate_add($r, "abdcde", ZLIB_FINISH);
12var_dump($a);
13
14$r = deflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => implode("\0", $dict)."\0"]);
15$dictStr_a = deflate_add($r, "abdcde", ZLIB_FINISH);
16var_dump($dictStr_a === $a);
17
18$r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => $dict]);
19var_dump(inflate_add($r, $a, ZLIB_FINISH));
20
21
22$r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => ["8"] + range("a", "z")]);
23var_dump(inflate_add($r, $a, ZLIB_FINISH));
24
25?>
26--EXPECTF--
27string(%d) "%s"
28bool(true)
29string(6) "abdcde"
30
31Warning: inflate_add(): dictionary does not match expected dictionary (incorrect adler32 hash) in %s on line %d
32bool(false)
33