Skip to content

Commit d27b117

Browse files
committed
ext/zlib: Refactor tests
- Move data into a subfolder - Remove ZPP tests - Fix various bugs within tests - Simplify some
1 parent 27e485d commit d27b117

File tree

84 files changed

+171
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+171
-698
lines changed

ext/zlib/tests/002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ $original = str_repeat("hallo php",4096);
88
$packed=gzcompress($original);
99
echo strlen($packed)." ".strlen($original)."\n";
1010
$unpacked=gzuncompress($packed);
11-
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
11+
if ($original === $unpacked) echo "Strings are equal\n";
1212

1313
/* with explicit compression level, length */
1414
$original = str_repeat("hallo php",4096);
1515
$packed=gzcompress($original, 9);
1616
echo strlen($packed)." ".strlen($original)."\n";
1717
$unpacked=gzuncompress($packed, 40000);
18-
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
18+
if ($original === $unpacked) echo "Strings are equal\n";
1919
?>
2020
--EXPECT--
2121
106 36864

ext/zlib/tests/003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ zlib
77
$original = str_repeat("hallo php",4096);
88
$packed = gzencode($original);
99
echo strlen($packed)." ".strlen($original). "\n";
10-
if (strcmp($original, gzdecode($packed)) == 0) echo "Strings are equal";
10+
if ($original === gzdecode($packed)) echo "Strings are equal\n";
1111
?>
1212
--EXPECT--
1313
118 36864

ext/zlib/tests/bug55544-win.phpt

5 Bytes
Binary file not shown.

ext/zlib/tests/bug60761.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
checks zlib compression output size is always the same
33
--EXTENSIONS--
44
zlib
5+
--INI--
6+
zlib.output_compression=4096
7+
zlib.output_compression_level=9
58
--CGI--
69
--FILE--
710
<?php
811

9-
// the INI directives from bug #60761 report
10-
ini_set('zlib.output_compression', '4096');
11-
ini_set('zlib.output_compression_level', '9');
12-
1312
// try to duplicate the original bug by running this as a CGI
1413
// test using ob_start and zlib.output_compression(or ob_gzhandler)
1514
// so it follows more of the original code-path than just calling

ext/zlib/tests/bug61139.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gzopen('someFile', 'c');
99
?>
1010
--CLEAN--
1111
<?php
12-
unlink('someFile');
12+
unlink('someFile');
1313
?>
1414
--EXPECTF--
1515
Warning: gzopen(): gzopen failed in %s on line %d

ext/zlib/tests/bug71417.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function test($case) {
4545
// The gzdecode() function applied to the corrupted compressed data always
4646
// detects the error:
4747
// --> gzdecode(): PHP Fatal error: Uncaught ErrorException: gzdecode(): data error in ...
48-
echo "gzdecode(): ", rawurldecode(gzdecode($compressed)), "\n";
48+
echo "gzdecode(): ", rawurldecode((string) gzdecode($compressed)), "\n";
4949

5050
file_put_contents($fn, $compressed);
5151

ext/zlib/tests/bug74240.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Bug #74240 (deflate_add can allocate too much memory)
33
--EXTENSIONS--
44
zlib
5+
--INI--
6+
memory_limit=64M
57
--FILE--
68
<?php
79

8-
ini_set('memory_limit', '64M');
9-
1010
$deflator = deflate_init(ZLIB_ENCODING_RAW);
1111

1212
$bytes = str_repeat("*", 65536);

ext/zlib/tests/compress_zlib_wrapper.phpt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ compress.zlib:// wrapper
44
zlib
55
--FILE--
66
<?php
7-
chdir(__DIR__. "/../../..");
8-
9-
$pfx = str_repeat('../', substr_count($_SERVER['PHP_SELF'], '../'));
7+
chdir(__DIR__. "/data");
108

119
// Relative path
12-
$fp = fopen("compress.zlib://{$pfx}ext/xsl/tests/xslt.xsl.gz", "rb");
10+
$fp = fopen("compress.zlib://test.txt.gz", "rb");
1311
fclose($fp);
1412

1513
// Absolute path
16-
$fp = fopen("compress.zlib://". __DIR__. "/../../../ext/xsl/tests/xslt.xsl.gz", "rb");
14+
$fp = fopen("compress.zlib://". __DIR__. "/data/test.txt.gz", "rb");
1715
fclose($fp);
1816

1917
echo "ok\n";
File renamed without changes.
File renamed without changes.
File renamed without changes.

ext/zlib/tests/deflate_init_reuse.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ foreach (range("a", "z") as $char) {
1717
$compressed .= deflate_add($resource, $char, ZLIB_NO_FLUSH);
1818
}
1919
$compressed .= deflate_add($resource, "", ZLIB_FINISH);
20-
assert($uncompressed === zlib_decode($compressed));
20+
var_dump($uncompressed === zlib_decode($compressed));
2121
?>
2222
===DONE===
2323
--EXPECT--
24+
bool(true)
2425
===DONE===

ext/zlib/tests/gh16883.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ stream_context_set_default([
2929
$f = gzopen('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r');
3030
var_dump(stream_get_contents($f));
3131

32-
var_dump(gzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r'));
32+
var_dump(gzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT));
3333

34-
var_dump(readgzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r'));
34+
var_dump(readgzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT));
3535

3636
?>
3737
--EXPECT--

ext/zlib/tests/gzclose_basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ zlib
77
// note that gzclose is an alias to fclose. parameter checking tests will be
88
// the same as fclose
99

10-
$f = __DIR__."/004.txt.gz";
10+
$f = __DIR__."/data/test.txt.gz";
1111
$h = gzopen($f, 'r');
1212
gzread($h, 20);
1313
var_dump(gzclose($h));

ext/zlib/tests/gzcompress_basic1.phpt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ zlib
88
* add a comment here to say what the test is supposed to do
99
*/
1010

11-
include(__DIR__ . '/data.inc');
11+
include(__DIR__ . '/data/data.inc');
1212

1313
echo "*** Testing gzcompress() : basic functionality ***\n";
1414

@@ -23,68 +23,68 @@ $smallstring = "A small string to compress\n";
2323
for($i = -1; $i < 10; $i++) {
2424
echo "-- Compression level $i --\n";
2525
$output = gzcompress($data, $i);
26-
var_dump(strcmp(gzuncompress($output), $data));
26+
var_dump(gzuncompress($output) === $data);
2727
}
2828

2929
// Compressing a smaller string
3030
for($i = -1; $i < 10; $i++) {
3131
echo "-- Compression level $i --\n";
3232
$output = gzcompress($smallstring, $i);
33-
var_dump(strcmp(gzuncompress($output), $smallstring));
33+
var_dump(gzuncompress($output) === $smallstring);
3434
}
3535

3636
// Calling gzcompress() with mandatory arguments
3737
echo "\n-- Testing with no specified compression level --\n";
3838
$output = gzcompress($smallstring);
39-
var_dump(strcmp(gzuncompress($output), $smallstring));
39+
var_dump(gzuncompress($output) === $smallstring);
4040

4141
?>
4242
--EXPECT--
4343
*** Testing gzcompress() : basic functionality ***
4444
-- Compression level -1 --
45-
int(0)
45+
bool(true)
4646
-- Compression level 0 --
47-
int(0)
47+
bool(true)
4848
-- Compression level 1 --
49-
int(0)
49+
bool(true)
5050
-- Compression level 2 --
51-
int(0)
51+
bool(true)
5252
-- Compression level 3 --
53-
int(0)
53+
bool(true)
5454
-- Compression level 4 --
55-
int(0)
55+
bool(true)
5656
-- Compression level 5 --
57-
int(0)
57+
bool(true)
5858
-- Compression level 6 --
59-
int(0)
59+
bool(true)
6060
-- Compression level 7 --
61-
int(0)
61+
bool(true)
6262
-- Compression level 8 --
63-
int(0)
63+
bool(true)
6464
-- Compression level 9 --
65-
int(0)
65+
bool(true)
6666
-- Compression level -1 --
67-
int(0)
67+
bool(true)
6868
-- Compression level 0 --
69-
int(0)
69+
bool(true)
7070
-- Compression level 1 --
71-
int(0)
71+
bool(true)
7272
-- Compression level 2 --
73-
int(0)
73+
bool(true)
7474
-- Compression level 3 --
75-
int(0)
75+
bool(true)
7676
-- Compression level 4 --
77-
int(0)
77+
bool(true)
7878
-- Compression level 5 --
79-
int(0)
79+
bool(true)
8080
-- Compression level 6 --
81-
int(0)
81+
bool(true)
8282
-- Compression level 7 --
83-
int(0)
83+
bool(true)
8484
-- Compression level 8 --
85-
int(0)
85+
bool(true)
8686
-- Compression level 9 --
87-
int(0)
87+
bool(true)
8888

8989
-- Testing with no specified compression level --
90-
int(0)
90+
bool(true)

ext/zlib/tests/gzcompress_error1.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ try {
2020
}
2121

2222
echo "\n-- Testing with invalid encoding --\n";
23-
$data = 'string_val';
2423
$level = 2;
2524
$encoding = 99;
2625
try {

ext/zlib/tests/gzcompress_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Test gzcompress() function : variation
44
zlib
55
--FILE--
66
<?php
7-
include(__DIR__ . '/data.inc');
7+
include(__DIR__ . '/data/data.inc');
88

99
echo "*** Testing gzcompress() : variation ***\n";
1010

ext/zlib/tests/gzdeflate_basic1.phpt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ zlib
88
* add a comment here to say what the test is supposed to do
99
*/
1010

11-
include(__DIR__ . '/data.inc');
11+
include(__DIR__ . '/data/data.inc');
1212

1313
echo "*** Testing gzdeflate() : basic functionality ***\n";
1414

@@ -23,68 +23,68 @@ $smallstring = "A small string to compress\n";
2323
for($i = -1; $i < 10; $i++) {
2424
echo "-- Compression level $i --\n";
2525
$output = gzdeflate($data, $i);
26-
var_dump(strcmp(gzinflate($output), $data));
26+
var_dump(gzinflate($output) === $data);
2727
}
2828

2929
// Compressing a smaller string
3030
for($i = -1; $i < 10; $i++) {
3131
echo "-- Compression level $i --\n";
3232
$output = gzdeflate($smallstring, $i);
33-
var_dump(strcmp(gzinflate($output), $smallstring));
33+
var_dump(gzinflate($output) === $smallstring);
3434
}
3535

3636
// Calling gzdeflate() with just mandatory arguments
3737
echo "\n-- Testing with no specified compression level --\n";
3838
$output = gzdeflate($smallstring);
39-
var_dump(strcmp(gzinflate($output), $smallstring));
39+
var_dump(gzinflate($output) === $smallstring);
4040

4141
?>
4242
--EXPECT--
4343
*** Testing gzdeflate() : basic functionality ***
4444
-- Compression level -1 --
45-
int(0)
45+
bool(true)
4646
-- Compression level 0 --
47-
int(0)
47+
bool(true)
4848
-- Compression level 1 --
49-
int(0)
49+
bool(true)
5050
-- Compression level 2 --
51-
int(0)
51+
bool(true)
5252
-- Compression level 3 --
53-
int(0)
53+
bool(true)
5454
-- Compression level 4 --
55-
int(0)
55+
bool(true)
5656
-- Compression level 5 --
57-
int(0)
57+
bool(true)
5858
-- Compression level 6 --
59-
int(0)
59+
bool(true)
6060
-- Compression level 7 --
61-
int(0)
61+
bool(true)
6262
-- Compression level 8 --
63-
int(0)
63+
bool(true)
6464
-- Compression level 9 --
65-
int(0)
65+
bool(true)
6666
-- Compression level -1 --
67-
int(0)
67+
bool(true)
6868
-- Compression level 0 --
69-
int(0)
69+
bool(true)
7070
-- Compression level 1 --
71-
int(0)
71+
bool(true)
7272
-- Compression level 2 --
73-
int(0)
73+
bool(true)
7474
-- Compression level 3 --
75-
int(0)
75+
bool(true)
7676
-- Compression level 4 --
77-
int(0)
77+
bool(true)
7878
-- Compression level 5 --
79-
int(0)
79+
bool(true)
8080
-- Compression level 6 --
81-
int(0)
81+
bool(true)
8282
-- Compression level 7 --
83-
int(0)
83+
bool(true)
8484
-- Compression level 8 --
85-
int(0)
85+
bool(true)
8686
-- Compression level 9 --
87-
int(0)
87+
bool(true)
8888

8989
-- Testing with no specified compression level --
90-
int(0)
90+
bool(true)

ext/zlib/tests/gzdeflate_variation1.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ Test gzdeflate() function : variation
44
zlib
55
--FILE--
66
<?php
7-
include(__DIR__ . '/data.inc');
7+
include(__DIR__ . '/data/data.inc');
88

99
echo "*** Testing gzdeflate() : variation ***\n";
1010

11-
12-
1311
echo "\n-- Testing multiple compression --\n";
1412
$output = gzdeflate($data);
1513
var_dump(strlen($output));

0 commit comments

Comments
 (0)