summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2005-12-12 06:17:16 +0000
committerGreg Beaver <cellog@php.net>2005-12-12 06:17:16 +0000
commitb4cc79277a2419a38bf7876880dd10a0f4488135 (patch)
tree1ade72aaf99f421e64c0dfceeb1c83c8fd30cec9
parenta13a4487a42f83bfc00f4ad918e7d96b1554fb91 (diff)
downloadphp-git-b4cc79277a2419a38bf7876880dd10a0f4488135.tar.gz
complete unit tests (woohoo!)
add stream seek (mistakenly never enabled)
-rw-r--r--ext/phar/EXPERIMENTAL4
-rw-r--r--ext/phar/phar.c4
-rw-r--r--ext/phar/tests/012.phpt1
-rw-r--r--ext/phar/tests/016.phpt2
-rw-r--r--ext/phar/tests/020.phpt135
-rw-r--r--ext/phar/tests/021.phpt83
-rw-r--r--ext/phar/tests/022.phpt112
7 files changed, 337 insertions, 4 deletions
diff --git a/ext/phar/EXPERIMENTAL b/ext/phar/EXPERIMENTAL
index e69de29bb2..f78e8f98cc 100644
--- a/ext/phar/EXPERIMENTAL
+++ b/ext/phar/EXPERIMENTAL
@@ -0,0 +1,4 @@
+TODO:
+
+features:
+- stream context option for cleaning crap paths like phar://blah.phar/file//to\\here.php \ No newline at end of file
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index 1c01faf7d8..58094ba5b4 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -360,7 +360,7 @@ static php_stream_ops phar_ops = {
phar_close, /* close */
phar_flush, /* flush (does nothing) */
"phar stream",
- NULL, /* seek */
+ phar_seek, /* seek */
NULL, /* cast */
phar_stat, /* stat */
NULL, /* set option */
@@ -708,7 +708,7 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe
efree(idata->file);
buffer = idata->data->file;
efree(idata);
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file);
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (actual filesize mismatch on file \"%s\")", buffer, internal_file);
efree(internal_file);
return NULL;
}
diff --git a/ext/phar/tests/012.phpt b/ext/phar/tests/012.phpt
index 9847c34015..71f624f680 100644
--- a/ext/phar/tests/012.phpt
+++ b/ext/phar/tests/012.phpt
@@ -9,7 +9,6 @@ register_shutdown_function('cleanup');
$file = "<?php
PHP_Archive::mapPhar(5, 'hio', false);
__HALT_COMPILER(); ?>";
-// compressed file length does not include 8 bytes for crc/file length and should
$manifest = pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9);
$file .= pack('VV', strlen($manifest) + 4, 1) . $manifest . pack('VV', crc32('a'), 1) . 'a';
file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
diff --git a/ext/phar/tests/016.phpt b/ext/phar/tests/016.phpt
index 0cbe5a336b..b92ef501c6 100644
--- a/ext/phar/tests/016.phpt
+++ b/ext/phar/tests/016.phpt
@@ -18,4 +18,4 @@ include dirname(__FILE__) . '/008_phar.php';
echo file_get_contents('phar://hio/a');
?>
--EXPECTF--
-Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: data error in %s on line %d \ No newline at end of file
+Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: decompression failed in %s on line %d \ No newline at end of file
diff --git a/ext/phar/tests/020.phpt b/ext/phar/tests/020.phpt
new file mode 100644
index 0000000000..53bf17a4f1
--- /dev/null
+++ b/ext/phar/tests/020.phpt
@@ -0,0 +1,135 @@
+--TEST--
+url stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+function cleanup() { unlink(dirname(__FILE__) . '/008_phar.php'); }
+register_shutdown_function('cleanup');
+$file = "<?php
+PHP_Archive::mapPhar(5, 'hio', false);
+__HALT_COMPILER(); ?>";
+$manifest = '';
+$manifest .= pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 3) . 'b/a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'b/c/d' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'bad/c' . pack('VVVV', 1, time(), 0, 9);
+$file .= pack('VV', strlen($manifest) + 4, 4) .
+ $manifest .
+ pack('VV', crc32('a'), 1) . 'a' .
+ pack('VV', crc32('b'), 1) . 'b';
+ pack('VV', crc32('c'), 1) . 'c';
+ pack('VV', crc32('d'), 1) . 'd';
+file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
+include dirname(__FILE__) . '/008_phar.php';
+var_dump(stat('phar://hio/a'), stat('phar://hio/b'));
+?>
+--EXPECTF--
+array(26) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(0)
+ [2]=>
+ int(33060)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(1)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(0)
+ ["ino"]=>
+ int(0)
+ ["mode"]=>
+ int(33060)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(1)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+}
+array(26) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(0)
+ [2]=>
+ int(16676)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(0)
+ [8]=>
+ int(0)
+ [9]=>
+ int(0)
+ [10]=>
+ int(0)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(0)
+ ["ino"]=>
+ int(0)
+ ["mode"]=>
+ int(16676)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(0)
+ ["atime"]=>
+ int(0)
+ ["mtime"]=>
+ int(0)
+ ["ctime"]=>
+ int(0)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+} \ No newline at end of file
diff --git a/ext/phar/tests/021.phpt b/ext/phar/tests/021.phpt
new file mode 100644
index 0000000000..a571b1ee28
--- /dev/null
+++ b/ext/phar/tests/021.phpt
@@ -0,0 +1,83 @@
+--TEST--
+stream stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+function cleanup() { unlink(dirname(__FILE__) . '/008_phar.php'); }
+register_shutdown_function('cleanup');
+$file = "<?php
+PHP_Archive::mapPhar(5, 'hio', false);
+__HALT_COMPILER(); ?>";
+$manifest = '';
+$manifest .= pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 3) . 'b/a' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'b/c/d' . pack('VVVV', 1, time(), 0, 9);
+$manifest .= pack('V', 5) . 'bad/c' . pack('VVVV', 1, time(), 0, 9);
+$file .= pack('VV', strlen($manifest) + 4, 4) .
+ $manifest .
+ pack('VV', crc32('a'), 1) . 'a' .
+ pack('VV', crc32('b'), 1) . 'b';
+ pack('VV', crc32('c'), 1) . 'c';
+ pack('VV', crc32('d'), 1) . 'd';
+file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
+include dirname(__FILE__) . '/008_phar.php';
+$fp = fopen('phar://hio/a', 'r');
+var_dump(fstat($fp));
+fclose($fp);
+?>
+--EXPECTF--
+array(26) {
+ [0]=>
+ int(0)
+ [1]=>
+ int(0)
+ [2]=>
+ int(33060)
+ [3]=>
+ int(1)
+ [4]=>
+ int(0)
+ [5]=>
+ int(0)
+ [6]=>
+ int(-1)
+ [7]=>
+ int(1)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-1)
+ [12]=>
+ int(-1)
+ ["dev"]=>
+ int(0)
+ ["ino"]=>
+ int(0)
+ ["mode"]=>
+ int(33060)
+ ["nlink"]=>
+ int(1)
+ ["uid"]=>
+ int(0)
+ ["gid"]=>
+ int(0)
+ ["rdev"]=>
+ int(-1)
+ ["size"]=>
+ int(1)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-1)
+ ["blocks"]=>
+ int(-1)
+} \ No newline at end of file
diff --git a/ext/phar/tests/022.phpt b/ext/phar/tests/022.phpt
new file mode 100644
index 0000000000..95a6fd8d2d
--- /dev/null
+++ b/ext/phar/tests/022.phpt
@@ -0,0 +1,112 @@
+--TEST--
+stream stat
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+function cleanup() { unlink(dirname(__FILE__) . '/008_phar.php'); }
+register_shutdown_function('cleanup');
+$file = "<?php
+PHP_Archive::mapPhar(5, 'hio', false);
+__HALT_COMPILER(); ?>";
+$contents = 'abcdefg';
+$manifest = pack('V', 1) . 'a' . pack('VVVV', strlen($contents), time(), 0, 8 + strlen($contents));
+$file .= pack('VV', strlen($manifest) + 4, 1) .
+ $manifest .
+ pack('VV', crc32($contents), strlen($contents)) . $contents;
+file_put_contents(dirname(__FILE__) . '/008_phar.php', $file);
+include dirname(__FILE__) . '/008_phar.php';
+$fp = fopen('phar://hio/a', 'r');
+var_dump(ftell($fp));
+echo 'fseek($fp, 1)';var_dump(fseek($fp, 1));
+var_dump(ftell($fp));
+echo 'fseek($fp, 1, SEEK_CUR)';var_dump(fseek($fp, 1, SEEK_CUR));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1, SEEK_CUR)';var_dump(fseek($fp, -1, SEEK_CUR));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1, SEEK_END)';var_dump(fseek($fp, -1, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -8, SEEK_END)';var_dump(fseek($fp, -8, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -7, SEEK_END)';var_dump(fseek($fp, -7, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 0, SEEK_END)';var_dump(fseek($fp, 0, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 1, SEEK_END)';var_dump(fseek($fp, 1, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, -8, SEEK_END)';var_dump(fseek($fp, -8, SEEK_END));
+var_dump(ftell($fp));
+echo 'fseek($fp, 6)';var_dump(fseek($fp, 6));
+var_dump(ftell($fp));
+echo 'fseek($fp, 8)';var_dump(fseek($fp, 8));
+var_dump(ftell($fp));
+echo 'fseek($fp, -1)';var_dump(fseek($fp, -1));
+var_dump(ftell($fp));
+echo "next\n";
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, -5, SEEK_CUR)';var_dump(fseek($fp, -5, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, 5, SEEK_CUR)';var_dump(fseek($fp, 5, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, -4, SEEK_CUR)';var_dump(fseek($fp, -4, SEEK_CUR));
+var_dump(ftell($fp));
+fseek($fp, 4);
+var_dump(ftell($fp));
+echo 'fseek($fp, 3, SEEK_CUR)';var_dump(fseek($fp, 3, SEEK_CUR));
+var_dump(ftell($fp));
+fclose($fp);
+?>
+--EXPECT--
+int(0)
+fseek($fp, 1)int(0)
+int(1)
+fseek($fp, 1, SEEK_CUR)int(0)
+int(2)
+fseek($fp, -1, SEEK_CUR)int(0)
+int(1)
+fseek($fp, -1, SEEK_END)int(0)
+int(6)
+fseek($fp, -8, SEEK_END)int(-1)
+bool(false)
+fseek($fp, -7, SEEK_END)int(0)
+int(0)
+fseek($fp, 0, SEEK_END)int(0)
+int(7)
+fseek($fp, 1, SEEK_END)int(-1)
+bool(false)
+fseek($fp, -8, SEEK_END)int(-1)
+bool(false)
+fseek($fp, 6)int(0)
+int(6)
+fseek($fp, 8)int(-1)
+bool(false)
+fseek($fp, -1)int(-1)
+bool(false)
+next
+int(4)
+fseek($fp, -5, SEEK_CUR)int(-1)
+bool(false)
+int(4)
+fseek($fp, 5, SEEK_CUR)int(-1)
+bool(false)
+int(4)
+fseek($fp, -4, SEEK_CUR)int(0)
+int(0)
+int(4)
+fseek($fp, 3, SEEK_CUR)int(0)
+int(7)
+
+
+
+
+
+
+
+
+
+