summaryrefslogtreecommitdiff
path: root/ext/bz2/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bz2/tests')
-rw-r--r--ext/bz2/tests/001.phpt43
-rw-r--r--ext/bz2/tests/002.phpt129
-rw-r--r--ext/bz2/tests/003.phpt40
-rw-r--r--ext/bz2/tests/003.txt.bz2bin0 -> 126 bytes
-rw-r--r--ext/bz2/tests/004.phpt111
-rw-r--r--ext/bz2/tests/004_1.txt.bz2bin0 -> 125 bytes
-rw-r--r--ext/bz2/tests/004_2.txt.bz2bin0 -> 123 bytes
-rw-r--r--ext/bz2/tests/005.phpt71
-rw-r--r--ext/bz2/tests/bug51997.phpt24
-rw-r--r--ext/bz2/tests/bz2_filter_compress.phpt17
-rw-r--r--ext/bz2/tests/bz2_filter_decompress.phpt17
-rw-r--r--ext/bz2/tests/with_files.phpt23
-rw-r--r--ext/bz2/tests/with_strings.phpt27
13 files changed, 502 insertions, 0 deletions
diff --git a/ext/bz2/tests/001.phpt b/ext/bz2/tests/001.phpt
new file mode 100644
index 0000000..47dbfe8
--- /dev/null
+++ b/ext/bz2/tests/001.phpt
@@ -0,0 +1,43 @@
+--TEST--
+bzopen() and invalid parameters
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(bzopen());
+var_dump(bzopen("", ""));
+var_dump(bzopen("", "r"));
+var_dump(bzopen("", "w"));
+var_dump(bzopen("", "x"));
+var_dump(bzopen("", "rw"));
+var_dump(bzopen("no_such_file", "r"));
+
+$fp = fopen(__FILE__,"r");
+var_dump(bzopen($fp, "r"));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: bzopen() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+
+Warning: bzopen(): '' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
+bool(false)
+
+Warning: bzopen(): filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: bzopen(): filename cannot be empty in %s on line %d
+bool(false)
+
+Warning: bzopen(): 'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
+bool(false)
+
+Warning: bzopen(): 'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d
+bool(false)
+
+Warning: bzopen(no_such_file): failed to open stream: No such file or directory in %s on line %d
+bool(false)
+resource(%d) of type (stream)
+Done
diff --git a/ext/bz2/tests/002.phpt b/ext/bz2/tests/002.phpt
new file mode 100644
index 0000000..c55e22d
--- /dev/null
+++ b/ext/bz2/tests/002.phpt
@@ -0,0 +1,129 @@
+--TEST--
+bzopen() using fd opened in wrong mode
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php
+
+@unlink("bz_open_002.txt");
+
+$fp = fopen("bz_open_002.txt", "w");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "r");
+var_dump(bzopen($fp, "r"));
+
+@unlink("bz_open_002.txt");
+$fp = fopen("bz_open_002.txt", "x");
+var_dump(bzopen($fp, "w"));
+
+@unlink("bz_open_002.txt");
+$fp = fopen("bz_open_002.txt", "x");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "rb");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "wb");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "br");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "br");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "r");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "w");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "rw");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "rw");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "wr");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "wr");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "r+");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "r+");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "w+");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "w+");
+var_dump(bzopen($fp, "w"));
+
+$fp = fopen("bz_open_002.txt", "a");
+var_dump(bzopen($fp, "r"));
+
+$fp = fopen("bz_open_002.txt", "a");
+var_dump(bzopen($fp, "w"));
+
+@unlink("bz_open_002.txt");
+
+echo "Done\n";
+?>
+--EXPECTF--
+resource(%d) of type (stream)
+resource(%d) of type (stream)
+resource(%d) of type (stream)
+
+Warning: bzopen(): cannot read from a stream opened in write only mode in %s on line %d
+bool(false)
+resource(%d) of type (stream)
+resource(%d) of type (stream)
+
+Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d
+
+Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d
+bool(false)
+
+Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d
+
+Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot write to a stream opened in read only mode in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot read from a stream opened in write only mode in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'rw' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'rw' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'wr' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'wr' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'r+' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'r+' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'w+' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot use stream opened in mode 'w+' in %s on line %d
+bool(false)
+
+Warning: bzopen(): cannot read from a stream opened in write only mode in %s on line %d
+bool(false)
+resource(%d) of type (stream)
+Done
diff --git a/ext/bz2/tests/003.phpt b/ext/bz2/tests/003.phpt
new file mode 100644
index 0000000..1432600
--- /dev/null
+++ b/ext/bz2/tests/003.phpt
@@ -0,0 +1,40 @@
+--TEST--
+bzread() tests
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php
+
+$fd = bzopen(dirname(__FILE__)."/003.txt.bz2","r");
+var_dump(bzread());
+var_dump(bzread($fd, 1 ,0));
+var_dump(bzread($fd, 0));
+var_dump(bzread($fd, -10));
+var_dump(bzread($fd, 1));
+var_dump(bzread($fd, 2));
+var_dump(bzread($fd, 100000));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: bzread() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: bzread() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+string(0) ""
+
+Warning: bzread(): length may not be negative in %s on line %d
+bool(false)
+string(1) "R"
+string(2) "is"
+string(251) "ing up from the heart of the desert
+Rising up for Jerusalem
+Rising up from the heat of the desert
+Building up Old Jerusalem
+Rising up from the heart of the desert
+Rising up for Jerusalem
+Rising up from the heat of the desert
+Heading out for Jerusalem
+"
+Done
diff --git a/ext/bz2/tests/003.txt.bz2 b/ext/bz2/tests/003.txt.bz2
new file mode 100644
index 0000000..034cd4d
--- /dev/null
+++ b/ext/bz2/tests/003.txt.bz2
Binary files differ
diff --git a/ext/bz2/tests/004.phpt b/ext/bz2/tests/004.phpt
new file mode 100644
index 0000000..a638188
--- /dev/null
+++ b/ext/bz2/tests/004.phpt
@@ -0,0 +1,111 @@
+--TEST--
+bzread() tests with invalid files
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php
+
+$fd = bzopen(dirname(__FILE__)."/004_1.txt.bz2","r");
+var_dump(bzerror($fd));
+var_dump(bzerrstr($fd));
+var_dump(bzerrno($fd));
+
+$fd2 = bzopen(dirname(__FILE__)."/004_2.txt.bz2","r");
+var_dump(bzerror($fd2));
+var_dump(bzerrstr($fd2));
+var_dump(bzerrno($fd2));
+
+var_dump(bzread($fd, 10));
+var_dump(bzerror($fd));
+var_dump(bzerrstr($fd));
+var_dump(bzerrno($fd));
+
+var_dump(bzread($fd2, 10));
+var_dump(bzerror($fd2));
+var_dump(bzerrstr($fd2));
+var_dump(bzerrno($fd2));
+
+var_dump(bzread($fd));
+var_dump(bzerror($fd));
+var_dump(bzerrstr($fd));
+var_dump(bzerrno($fd));
+
+var_dump(bzread($fd2));
+var_dump(bzerror($fd2));
+var_dump(bzerrstr($fd2));
+var_dump(bzerrno($fd2));
+
+bzclose($fd2);
+var_dump(bzread($fd2));
+var_dump(bzerror($fd2));
+var_dump(bzerrstr($fd2));
+var_dump(bzerrno($fd2));
+
+echo "Done\n";
+?>
+--EXPECTF--
+array(2) {
+ ["errno"]=>
+ int(0)
+ ["errstr"]=>
+ string(2) "OK"
+}
+string(2) "OK"
+int(0)
+array(2) {
+ ["errno"]=>
+ int(0)
+ ["errstr"]=>
+ string(2) "OK"
+}
+string(2) "OK"
+int(0)
+string(0) ""
+array(2) {
+ ["errno"]=>
+ int(-5)
+ ["errstr"]=>
+ string(16) "DATA_ERROR_MAGIC"
+}
+string(16) "DATA_ERROR_MAGIC"
+int(-5)
+string(0) ""
+array(2) {
+ ["errno"]=>
+ int(-4)
+ ["errstr"]=>
+ string(10) "DATA_ERROR"
+}
+string(10) "DATA_ERROR"
+int(-4)
+string(0) ""
+array(2) {
+ ["errno"]=>
+ int(-5)
+ ["errstr"]=>
+ string(16) "DATA_ERROR_MAGIC"
+}
+string(16) "DATA_ERROR_MAGIC"
+int(-5)
+string(0) ""
+array(2) {
+ ["errno"]=>
+ int(-4)
+ ["errstr"]=>
+ string(10) "DATA_ERROR"
+}
+string(10) "DATA_ERROR"
+int(-4)
+
+Warning: bzread(): %d is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: bzerror(): %d is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: bzerrstr(): %d is not a valid stream resource in %s on line %d
+bool(false)
+
+Warning: bzerrno(): %d is not a valid stream resource in %s on line %d
+bool(false)
+Done
diff --git a/ext/bz2/tests/004_1.txt.bz2 b/ext/bz2/tests/004_1.txt.bz2
new file mode 100644
index 0000000..6a5067b
--- /dev/null
+++ b/ext/bz2/tests/004_1.txt.bz2
Binary files differ
diff --git a/ext/bz2/tests/004_2.txt.bz2 b/ext/bz2/tests/004_2.txt.bz2
new file mode 100644
index 0000000..9c19f04
--- /dev/null
+++ b/ext/bz2/tests/004_2.txt.bz2
Binary files differ
diff --git a/ext/bz2/tests/005.phpt b/ext/bz2/tests/005.phpt
new file mode 100644
index 0000000..da29a6d
--- /dev/null
+++ b/ext/bz2/tests/005.phpt
@@ -0,0 +1,71 @@
+--TEST--
+bzcompress()/bzdecompress() tests
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php
+
+$string = "Life it seems, will fade away
+Drifting further everyday
+Getting lost within myself
+Nothing matters no one else";
+
+var_dump(bzcompress());
+var_dump(bzcompress(1,1,1));
+var_dump(bzcompress($string, 100));
+var_dump(bzcompress($string, 100, -1));
+var_dump(bzcompress($string, 100, 1000));
+var_dump(bzcompress($string, -1, 1));
+
+$data = bzcompress($string);
+$data2 = bzcompress($string, 1, 10);
+
+$data3 = $data2;
+$data3{3} = 0;
+
+var_dump(bzdecompress());
+var_dump(bzdecompress(1,1,1));
+var_dump(bzdecompress(1,1));
+var_dump(bzdecompress($data3));
+var_dump(bzdecompress($data3,1));
+
+var_dump(bzdecompress($data, -1));
+var_dump(bzdecompress($data, 0));
+var_dump(bzdecompress($data, 1000));
+var_dump(bzdecompress($data));
+var_dump(bzdecompress($data2));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: bzcompress() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+string(%d) "BZ%a"
+int(-2)
+int(-2)
+int(-2)
+int(-2)
+
+Warning: bzdecompress() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: bzdecompress() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+int(-5)
+int(-5)
+int(-5)
+bool(false)
+string(110) "Life it seems, will fade away
+Drifting further everyday
+Getting lost within myself
+Nothing matters no one else"
+bool(false)
+string(110) "Life it seems, will fade away
+Drifting further everyday
+Getting lost within myself
+Nothing matters no one else"
+string(110) "Life it seems, will fade away
+Drifting further everyday
+Getting lost within myself
+Nothing matters no one else"
+Done
diff --git a/ext/bz2/tests/bug51997.phpt b/ext/bz2/tests/bug51997.phpt
new file mode 100644
index 0000000..fea5398
--- /dev/null
+++ b/ext/bz2/tests/bug51997.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #51997 (SEEK_CUR with 0 value, returns a warning)
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php
+
+error_reporting(E_ALL);
+
+$filename = "testfile.bz2";
+$str = "This is a test string.\n";
+$bz = bzopen($filename, "w");
+bzwrite($bz, $str);
+bzclose($bz);
+
+$bz = bzopen($filename, "r");
+fseek($bz, 0, SEEK_CUR);
+print bzread($bz, 10);
+print bzread($bz);
+bzclose($bz);
+unlink($filename);
+
+--EXPECT--
+This is a test string.
diff --git a/ext/bz2/tests/bz2_filter_compress.phpt b/ext/bz2/tests/bz2_filter_compress.phpt
new file mode 100644
index 0000000..3de9a9d
--- /dev/null
+++ b/ext/bz2/tests/bz2_filter_compress.phpt
@@ -0,0 +1,17 @@
+--TEST--
+bzip2.compress (with convert.base64-encode)
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php /* $Id$ */
+$text = 'I am the very model of a modern major general, I\'ve information vegetable, animal, and mineral.';
+
+$fp = fopen('php://stdout', 'w');
+stream_filter_append($fp, 'bzip2.compress', STREAM_FILTER_WRITE);
+stream_filter_append($fp, 'convert.base64-encode', STREAM_FILTER_WRITE);
+fwrite($fp, $text);
+fclose($fp);
+
+?>
+--EXPECT--
+QlpoNDFBWSZTWRN6QG0AAAoVgECFACA395UgIABIintI1N6mpowIQ0E1MTTAQGYTNcRyMZm5kgW3ib7hVboE7Tmqj3ToGZ5G3q1ZauD2G58hibSck8KS95EEAbx1Cn+LuSKcKEgJvSA2gA==
diff --git a/ext/bz2/tests/bz2_filter_decompress.phpt b/ext/bz2/tests/bz2_filter_decompress.phpt
new file mode 100644
index 0000000..951d572
--- /dev/null
+++ b/ext/bz2/tests/bz2_filter_decompress.phpt
@@ -0,0 +1,17 @@
+--TEST--
+bzip2.decompress (with convert.base64-decode)
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php /* $Id$ */
+$text = 'QlpoNDFBWSZTWRN6QG0AAAoVgECFACA395UgIABIintI1N6mpowIQ0E1MTTAQGYTNcRyMZm5kgW3ib7hVboE7Tmqj3ToGZ5G3q1ZauD2G58hibSck8KS95EEAbx1Cn+LuSKcKEgJvSA2gA==';
+
+$fp = fopen('php://stdout', 'w');
+stream_filter_append($fp, 'convert.base64-decode', STREAM_FILTER_WRITE);
+stream_filter_append($fp, 'bzip2.decompress', STREAM_FILTER_WRITE);
+fwrite($fp, $text);
+fclose($fp);
+
+?>
+--EXPECT--
+I am the very model of a modern major general, I've information vegetable, animal, and mineral.
diff --git a/ext/bz2/tests/with_files.phpt b/ext/bz2/tests/with_files.phpt
new file mode 100644
index 0000000..5691445
--- /dev/null
+++ b/ext/bz2/tests/with_files.phpt
@@ -0,0 +1,23 @@
+--TEST--
+BZ2 with files
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php // $Id$
+
+error_reporting(E_ALL);
+
+$filename = "testfile.bz2";
+$str = "This is a test string.\n";
+$bz = bzopen($filename, "w");
+bzwrite($bz, $str);
+bzclose($bz);
+
+$bz = bzopen($filename, "r");
+print bzread($bz, 10);
+print bzread($bz);
+bzclose($bz);
+unlink($filename);
+
+--EXPECT--
+This is a test string.
diff --git a/ext/bz2/tests/with_strings.phpt b/ext/bz2/tests/with_strings.phpt
new file mode 100644
index 0000000..adf07e1
--- /dev/null
+++ b/ext/bz2/tests/with_strings.phpt
@@ -0,0 +1,27 @@
+--TEST--
+BZ2 with strings
+--SKIPIF--
+<?php if (!extension_loaded("bz2")) print "skip"; ?>
+--FILE--
+<?php // $Id$
+
+error_reporting(E_ALL);
+
+# This FAILS
+$blaat = <<<HEREDOC
+This is some random data
+HEREDOC;
+
+# This Works: (so, is heredoc related)
+#$blaat= 'This is some random data';
+
+$blaat2 = bzdecompress(bzcompress($blaat));
+
+$tests = <<<TESTS
+ \$blaat === \$blaat2
+TESTS;
+
+include(dirname(__FILE__) . '/../../../tests/quicktester.inc');
+
+--EXPECT--
+OK