xref: /PHP-7.0/ext/zlib/tests/gzencode_basic1.phpt (revision 11d24c15)
1--TEST--
2Test gzencode() function : basic functionality
3--SKIPIF--
4<?php
5if (!extension_loaded("zlib")) {
6	print "skip - ZLIB extension not loaded";
7}
8?>
9--FILE--
10<?php
11/* Prototype  : string gzencode  ( string $data  [, int $level  [, int $encoding_mode  ]] )
12 * Description: Gzip-compress a string
13 * Source code: ext/zlib/zlib.c
14 * Alias to functions:
15 */
16
17/*
18 * Test basic function of gzencode
19 */
20
21include(dirname(__FILE__) . '/data.inc');
22
23echo "*** Testing gzencode() : basic functionality ***\n";
24
25// Initialise all required variables
26
27$smallstring = "A small string to compress\n";
28
29
30// Calling gzencode() with various compression levels
31
32// Compressing a big string
33for($i = -1; $i < 10; $i++) {
34    echo "-- Compression level $i --\n";
35    $output = gzencode($data, $i);
36
37    // Clear OS byte before encode
38	$output[9] = "\x00";
39
40    var_dump(md5($output));
41}
42
43// Compressing a smaller string
44for($i = -1; $i < 10; $i++) {
45    echo "-- Compression level $i --\n";
46    $output = gzencode($smallstring, $i);
47
48    // Clear OS byte before encode
49	$output[9] = "\x00";
50
51    var_dump(md5($output));
52}
53
54// Calling gzencode() with mandatory arguments
55echo "\n-- Testing with no specified compression level --\n";
56var_dump(bin2hex(gzencode($smallstring)));
57
58echo "\n-- Testing gzencode with mode specified --\n";
59var_dump(bin2hex(gzencode($smallstring, -1, FORCE_GZIP)));
60
61?>
62===Done===
63--EXPECTF--
64*** Testing gzencode() : basic functionality ***
65-- Compression level -1 --
66string(32) "d9ede02415ce91d21e5a94274e2b9c42"
67-- Compression level 0 --
68string(32) "bbf32d5508e5f1f4e6d42790489dae15"
69-- Compression level 1 --
70string(32) "0bfaaa7a5a57f8fb533074fca6c85eeb"
71-- Compression level 2 --
72string(32) "7ddbfed63a76c42808722b66f1c133fc"
73-- Compression level 3 --
74string(32) "ca2b85d194dfa2a4e8a162b646c99265"
75-- Compression level 4 --
76string(32) "cfe28033eaf260bc33ddc04b53d3ba39"
77-- Compression level 5 --
78string(32) "ae357fada2b515422f8bea0aa3bcc48f"
79-- Compression level 6 --
80string(32) "d9ede02415ce91d21e5a94274e2b9c42"
81-- Compression level 7 --
82string(32) "d9ede02415ce91d21e5a94274e2b9c42"
83-- Compression level 8 --
84string(32) "d9ede02415ce91d21e5a94274e2b9c42"
85-- Compression level 9 --
86string(32) "0f220a09e9895bcb3a1308d2bc99cfdf"
87-- Compression level -1 --
88string(32) "f77bd31e1e4dd11d12828fb661a08010"
89-- Compression level 0 --
90string(32) "9c5005db88490d6fe102ea2c233b2872"
91-- Compression level 1 --
92string(32) "d24ff7c4c20cef69b9c3abd603368db9"
93-- Compression level 2 --
94string(32) "f77bd31e1e4dd11d12828fb661a08010"
95-- Compression level 3 --
96string(32) "f77bd31e1e4dd11d12828fb661a08010"
97-- Compression level 4 --
98string(32) "f77bd31e1e4dd11d12828fb661a08010"
99-- Compression level 5 --
100string(32) "f77bd31e1e4dd11d12828fb661a08010"
101-- Compression level 6 --
102string(32) "f77bd31e1e4dd11d12828fb661a08010"
103-- Compression level 7 --
104string(32) "f77bd31e1e4dd11d12828fb661a08010"
105-- Compression level 8 --
106string(32) "f77bd31e1e4dd11d12828fb661a08010"
107-- Compression level 9 --
108string(32) "8849e9a1543c04b3f882b5ce20839ed2"
109
110-- Testing with no specified compression level --
111string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000"
112
113-- Testing gzencode with mode specified --
114string(94) "1f8b08000000000000%c%c735428ce4dccc951282e29cacc4b5728c95748cecf2d284a2d2ee60200edc4e40b1b000000"
115===Done===
116