]> granicus.if.org Git - php/commitdiff
complete unit tests (woohoo!)
authorGreg Beaver <cellog@php.net>
Mon, 12 Dec 2005 06:17:16 +0000 (06:17 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 12 Dec 2005 06:17:16 +0000 (06:17 +0000)
add stream seek (mistakenly never enabled)

ext/phar/EXPERIMENTAL
ext/phar/phar.c
ext/phar/tests/012.phpt
ext/phar/tests/016.phpt
ext/phar/tests/020.phpt [new file with mode: 0644]
ext/phar/tests/021.phpt [new file with mode: 0644]
ext/phar/tests/022.phpt [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f78e8f98ccc5bb494a919b04bc7d402f2a69ffb0 100644 (file)
@@ -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
index 1c01faf7d82183c295601205720484df6aad332b..58094ba5b409b3bbc2304a95c6abc21a7689c73b 100644 (file)
@@ -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;
                }
index 9847c3401574bbbad84dd12703900aaf3bae858e..71f624f6804cdbf6d0a82866e2b1233cc1a6a2d7 100644 (file)
@@ -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);
index 0cbe5a336bf799d382be4ca74d08468fc584bdd3..b92ef501c6f0c30a74c5f26749cf42d6c541e39d 100644 (file)
@@ -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 (file)
index 0000000..53bf17a
--- /dev/null
@@ -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 (file)
index 0000000..a571b1e
--- /dev/null
@@ -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 (file)
index 0000000..95a6fd8
--- /dev/null
@@ -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)
+
+
+
+
+
+
+
+
+
+