diff options
| author | SVN Migration <svn@php.net> | 2003-02-27 17:43:39 +0000 |
|---|---|---|
| committer | SVN Migration <svn@php.net> | 2003-02-27 17:43:39 +0000 |
| commit | 078bcec0997ad0e07b720c43cc9e6d0e046a75ab (patch) | |
| tree | 36cb0f6be2ef078fe3374de8c087b93ecf82f812 /ext/standard/tests/file | |
| parent | fd61f69077f6156ca71dde60ecfd9ed9765a02db (diff) | |
| download | php-git-PHP-5.tar.gz | |
This commit was manufactured by cvs2svn to create branch 'PHP_5'.PHP-5
Diffstat (limited to 'ext/standard/tests/file')
| -rw-r--r-- | ext/standard/tests/file/001-win32.phpt | 127 | ||||
| -rw-r--r-- | ext/standard/tests/file/001.phpt | 148 | ||||
| -rw-r--r-- | ext/standard/tests/file/002.phpt | 54 | ||||
| -rw-r--r-- | ext/standard/tests/file/003.phpt | 43 | ||||
| -rw-r--r-- | ext/standard/tests/file/bug12556.phpt | 50 | ||||
| -rw-r--r-- | ext/standard/tests/file/bug20424.phpt | 12 | ||||
| -rw-r--r-- | ext/standard/tests/file/bug22382.phpt | 27 | ||||
| -rw-r--r-- | ext/standard/tests/file/bug22414.phpt | 38 | ||||
| -rw-r--r-- | ext/standard/tests/file/fopencookie.phpt | 86 | ||||
| -rw-r--r-- | ext/standard/tests/file/test.csv | 17 | ||||
| -rw-r--r-- | ext/standard/tests/file/test2.csv | 1 | ||||
| -rw-r--r-- | ext/standard/tests/file/userfilters.phpt | 60 | ||||
| -rw-r--r-- | ext/standard/tests/file/userstreams.phpt | 325 |
13 files changed, 0 insertions, 988 deletions
diff --git a/ext/standard/tests/file/001-win32.phpt b/ext/standard/tests/file/001-win32.phpt deleted file mode 100644 index d18ee325a6..0000000000 --- a/ext/standard/tests/file/001-win32.phpt +++ /dev/null @@ -1,127 +0,0 @@ ---TEST-- -File type functions ---SKIPIF-- -<?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - die('skip only for Windows'); -} -?> ---POST-- ---GET-- ---FILE-- -<?php -chdir(dirname(__FILE__)); -@unlink('test.file'); -@unlink('test.link'); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -fclose (fopen('test.file', 'w')); -chmod ('test.file', 0744); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -sleep (2); -if (file_exists('test.link')) { - echo "test.link exists\n"; -} else { - echo "test.link does not exist\n"; -} -if (is_link('test.file')) { - echo "test.file is a symlink\n"; -} else { - echo "test.file is not a symlink\n"; -} -if (is_link('test.link')) { - echo "test.link is a symlink\n"; -} else { - echo "test.link is not a symlink\n"; -} -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -$s = stat ('test.file'); -$ls = lstat ('test.file'); -for ($i = 0; $i <= 12; $i++) { - if ($ls[$i] != $s[$i]) { - echo "test.file lstat and stat differ at element $i\n"; - } -} -echo "test.file is " . filetype('test.file') . "\n"; -echo "test.link is " . filetype('test.link') . "\n"; -printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file')); -echo "test.file size is " . filesize('test.file') . "\n"; -if (is_writeable('test.file')) { - echo "test.file is writeable\n"; -} else { - echo "test.file is not writeable\n"; -} -if (is_readable('test.file')) { - echo "test.file is readable\n"; -} else { - echo "test.file is not readable\n"; -} -if (is_file('test.file')) { - echo "test.file is a regular file\n"; -} else { - echo "test.file is not a regular file\n"; -} -if (is_file('test.link')) { - echo "test.link is a regular file\n"; -} else { - echo "test.link is not a regular file\n"; -} -if (is_dir('test.link')) { - echo "test.link is a directory\n"; -} else { - echo "test.link is not a directory\n"; -} -if (is_dir('../file')) { - echo "../file is a directory\n"; -} else { - echo "../file is not a directory\n"; -} -if (is_dir('test.file')) { - echo "test.file is a directory\n"; -} else { - echo "test.file is not a directory\n"; -} -unlink('test.file'); -if (file_exists('test.file')) { - echo "test.file exists (cached)\n"; -} else { - echo "test.file does not exist\n"; -} -clearstatcache(); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -?> ---EXPECT-- -test.file does not exist -test.file exists -test.link does not exist -test.file is not a symlink -test.link is not a symlink -test.file exists -test.file is file -test.link is file -test.file permissions are 0666 -test.file size is 0 -test.file is writeable -test.file is readable -test.file is a regular file -test.link is not a regular file -test.link is not a directory -../file is a directory -test.file is not a directory -test.file does not exist -test.file does not exist diff --git a/ext/standard/tests/file/001.phpt b/ext/standard/tests/file/001.phpt deleted file mode 100644 index 2191fa23d6..0000000000 --- a/ext/standard/tests/file/001.phpt +++ /dev/null @@ -1,148 +0,0 @@ ---TEST-- -File type functions ---SKIPIF-- -<?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip no symlinks on Windows'); -} -?> ---POST-- ---GET-- ---FILE-- -<?php -chdir(dirname(__FILE__)); -@unlink('test.file'); -@unlink('test.link'); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -fclose (fopen('test.file', 'w')); -chmod ('test.file', 0744); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -sleep (2); -symlink('test.file','test.link'); -if (file_exists('test.link')) { - echo "test.link exists\n"; -} else { - echo "test.link does not exist\n"; -} -if (is_link('test.file')) { - echo "test.file is a symlink\n"; -} else { - echo "test.file is not a symlink\n"; -} -if (is_link('test.link')) { - echo "test.link is a symlink\n"; -} else { - echo "test.link is not a symlink\n"; -} -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -$s = stat ('test.file'); -$ls = lstat ('test.file'); -for ($i = 0; $i <= 12; $i++) { - if ($ls[$i] != $s[$i]) { - echo "test.file lstat and stat differ at element $i\n"; - } -} -$s = stat ('test.link'); -$ls = lstat ('test.link'); -for ($i = 0; $i <= 11; $i++) { - if ($ls[$i] != $s[$i]) { - if ($i != 6 && $i != 11) echo "test.link lstat and stat differ at element $i\n"; - } -} -echo "test.file is " . filetype('test.file') . "\n"; -echo "test.link is " . filetype('test.link') . "\n"; -printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file')); -echo "test.file size is " . filesize('test.file') . "\n"; -if (is_writeable('test.file')) { - echo "test.file is writeable\n"; -} else { - echo "test.file is not writeable\n"; -} -if (is_readable('test.file')) { - echo "test.file is readable\n"; -} else { - echo "test.file is not readable\n"; -} -if (is_executable('test.file')) { - echo "test.file is executable\n"; -} else { - echo "test.file is not executable\n"; -} -if (is_file('test.file')) { - echo "test.file is a regular file\n"; -} else { - echo "test.file is not a regular file\n"; -} -if (is_file('test.link')) { - echo "test.link is a regular file\n"; -} else { - echo "test.link is not a regular file\n"; -} -if (is_dir('test.link')) { - echo "test.link is a directory\n"; -} else { - echo "test.link is not a directory\n"; -} -if (is_dir('../file')) { - echo "../file is a directory\n"; -} else { - echo "../file is not a directory\n"; -} -if (is_dir('test.file')) { - echo "test.file is a directory\n"; -} else { - echo "test.file is not a directory\n"; -} -unlink('test.file'); -unlink('test.link'); -if (file_exists('test.file')) { - echo "test.file exists (cached)\n"; -} else { - echo "test.file does not exist\n"; -} -clearstatcache(); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -?> ---EXPECT-- -test.file does not exist -test.file exists -test.link exists -test.file is not a symlink -test.link is a symlink -test.file exists -test.link lstat and stat differ at element 1 -test.link lstat and stat differ at element 2 -test.link lstat and stat differ at element 7 -test.link lstat and stat differ at element 8 -test.link lstat and stat differ at element 9 -test.link lstat and stat differ at element 10 -test.file is file -test.link is link -test.file permissions are 0744 -test.file size is 0 -test.file is writeable -test.file is readable -test.file is executable -test.file is a regular file -test.link is a regular file -test.link is not a directory -../file is a directory -test.file is not a directory -test.file does not exist -test.file does not exist diff --git a/ext/standard/tests/file/002.phpt b/ext/standard/tests/file/002.phpt deleted file mode 100644 index 4642bac366..0000000000 --- a/ext/standard/tests/file/002.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -File/Stream functions ---POST-- ---GET-- ---FILE-- -<?php - -$data = <<<EOD -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -EOD; - -$name = tempnam("./ext/standard/tests/file/", "php"); -$fp = fopen($name, "w"); -fwrite($fp, $data); -fclose($fp); - -//readfile($name); -echo file_get_contents($name); - -unlink($name); - -?> ---EXPECT-- -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah diff --git a/ext/standard/tests/file/003.phpt b/ext/standard/tests/file/003.phpt deleted file mode 100644 index 2b75bdccee..0000000000 --- a/ext/standard/tests/file/003.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -is_*() and file_exists() return values are boolean. ---POST-- ---GET-- ---FILE-- -<?php - -$funcs = array( - 'is_writable', - 'is_readable', - 'is_executable', - 'is_file', - 'file_exists', -); - -$filename=""; - -foreach ($funcs as $test) { - $bb = $test($filename); - echo gettype($bb)."\n"; - clearstatcache(); -} - -$filename="run-tests.php"; - -foreach ($funcs as $test) { - $bb = $test($filename); - echo gettype($bb)."\n"; - clearstatcache(); -} - -?> ---EXPECT-- -boolean -boolean -boolean -boolean -boolean -boolean -boolean -boolean -boolean -boolean diff --git a/ext/standard/tests/file/bug12556.phpt b/ext/standard/tests/file/bug12556.phpt deleted file mode 100644 index 6d8763245f..0000000000 --- a/ext/standard/tests/file/bug12556.phpt +++ /dev/null @@ -1,50 +0,0 @@ ---TEST-- -Bug #12556: fgetcvs ignores lengths when quotes not closed ---POST-- ---GET-- ---FILE-- -<?php -$fp = fopen(dirname(__FILE__)."/test.csv", "r"); -while($line = fgetcsv($fp, 24)) { - $line = str_replace("\x0d\x0a", "\x0a", $line); - var_dump($line); -} -fclose($fp); -?> ---EXPECT-- -array(4) { - [0]=> - string(1) "6" - [1]=> - string(1) "7" - [2]=> - string(1) "8" - [3]=> - string(5) "line1" -} -array(4) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" - [2]=> - string(1) "3" - [3]=> - string(186) "line2 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -" -} diff --git a/ext/standard/tests/file/bug20424.phpt b/ext/standard/tests/file/bug20424.phpt deleted file mode 100644 index 0352d46f8e..0000000000 --- a/ext/standard/tests/file/bug20424.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Bug #20424: stream_get_meta_data craches on a normal file stream ---POST-- ---GET-- ---FILE-- -<?php -$f = fopen("run-tests.php", "r"); -$dummy = var_export(stream_get_meta_data($f), TRUE); -echo "I'm alive!\n"; -?> ---EXPECT-- -I'm alive! diff --git a/ext/standard/tests/file/bug22382.phpt b/ext/standard/tests/file/bug22382.phpt deleted file mode 100644 index 5255eaf350..0000000000 --- a/ext/standard/tests/file/bug22382.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Bug #22382: fgetcvs does not handle escaped quotes correctly ---POST-- ---GET-- ---FILE-- -<?php -$fp = fopen(dirname(__FILE__)."/test2.csv", "r"); -while(($line = fgetcsv($fp, 1024))) { - var_dump($line); -} -fclose($fp); -?> ---EXPECT-- -array(6) { - [0]=> - string(3) "One" - [1]=> - string(7) "\"Two\"" - [2]=> - string(7) "Three\"" - [3]=> - string(4) "Four" - [4]=> - string(2) "\\" - [5]=> - string(28) "\\\\\\\\\\\\\\\\\\\\\\\"\\\\" -}
\ No newline at end of file diff --git a/ext/standard/tests/file/bug22414.phpt b/ext/standard/tests/file/bug22414.phpt deleted file mode 100644 index 809ce50014..0000000000 --- a/ext/standard/tests/file/bug22414.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -Bug #22414: passthru() does not read data correctly ---SKIPIF-- -<?php - $cat_path = @shell_exec("which cat"); - if (empty($cat_path)) { - die('skip cat binary needed for this test is not avaliable'); - } -?> ---POST-- ---GET-- ---FILE-- -<?php - $php = getenv('TEST_PHP_EXECUTABLE'); - $pwd = realpath(dirname(__FILE__)); - - /* Regular Data Test */ - passthru($php . ' -r " echo \"HELLO\"; "'); - - echo "\n"; - - /* Binary Data Test */ - @unlink($pwd . '/passthru_test'); - - $cmd = $php . ' -r \' passthru("cat ' . $php . '"); \' > ' . $pwd . '/passthru_test'; - exec($cmd); - - if (md5_file($php) == md5_file($pwd . '/passthru_test')) { - echo "Works\n"; - } else { - echo "Does not work\n"; - } - - @unlink($pwd . '/passthru_test'); -?> ---EXPECT-- -HELLO -Works diff --git a/ext/standard/tests/file/fopencookie.phpt b/ext/standard/tests/file/fopencookie.phpt deleted file mode 100644 index 4043f85f89..0000000000 --- a/ext/standard/tests/file/fopencookie.phpt +++ /dev/null @@ -1,86 +0,0 @@ ---TEST-- -fopencookie detected and working (or cast mechanism works) ---FILE-- -<?php -# vim600:syn=php: - -/* This test verifies that the casting mechanism is working correctly. - * On systems with fopencookie, a FILE* is created around the user - * stream and that is passed back to the ZE to include. - * On systems without fopencookie, the stream is fed into a temporary - * file, and that temporary file is passed back to the ZE. - * The important thing here is really fopencookie; the glibc people - * changed the binary interface, so if haven't detected it correctly, - * you can expect this test to segfault. - * - * FIXME: the test really needs something to fseek(3) on the FILE* - * used internally for this test to be really effective. - */ - -class userstream { - var $position = 0; - var $data = "If you can read this, it worked"; - - function stream_open($path, $mode, $options, &$opened_path) - { - return true; - } - - function stream_read($count) - { - $ret = substr($this->data, $this->position, $count); - $this->position += strlen($ret); - return $ret; - } - - function stream_tell() - { - return $this->position; - } - - function stream_eof() - { - return $this->position >= strlen($this->data); - } - - function stream_seek($offset, $whence) - { - switch($whence) { - case SEEK_SET: - if ($offset < strlen($this->data) && $offset >= 0) { - $this->position = $offset; - return true; - } else { - return false; - } - break; - case SEEK_CUR: - if ($offset >= 0) { - $this->position += $offset; - return true; - } else { - return false; - } - break; - case SEEK_END: - if (strlen($this->data) + $offset >= 0) { - $this->position = strlen($this->data) + $offset; - return true; - } else { - return false; - } - break; - default: - return false; - } - } - -} - -stream_register_wrapper("cookietest", "userstream"); - -include("cookietest://foo"); - -?> ---EXPECT-- -If you can read this, it worked diff --git a/ext/standard/tests/file/test.csv b/ext/standard/tests/file/test.csv deleted file mode 100644 index d99984c2ab..0000000000 --- a/ext/standard/tests/file/test.csv +++ /dev/null @@ -1,17 +0,0 @@ -6,7,8,line1 -1,2,3,"line2 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 diff --git a/ext/standard/tests/file/test2.csv b/ext/standard/tests/file/test2.csv deleted file mode 100644 index d816464170..0000000000 --- a/ext/standard/tests/file/test2.csv +++ /dev/null @@ -1 +0,0 @@ -"One","\"Two\"","Three\"","Four","\\","\\\\\\\\\\\\\\\\\\\\\\\"\\\\" diff --git a/ext/standard/tests/file/userfilters.phpt b/ext/standard/tests/file/userfilters.phpt deleted file mode 100644 index 9c42e8e7f6..0000000000 --- a/ext/standard/tests/file/userfilters.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -User-space filters ---FILE-- -<?php -# vim600:syn=php: - -class UpperCaseFilter extends php_user_filter { - function oncreate() - { - echo "oncreate:\n"; - var_dump($this->filtername); - var_dump($this->params); - } - - function flush($closing) - { - echo "flush:\n"; - } - - function onclose() - { - echo "onclose:\n"; - } - - function write($data) - { - echo "write:\n"; - $x = parent::write($data); - return strlen($data); - } - - function read($bytes) - { - echo "read:\n"; - $x = parent::read($bytes); - return strtoupper($x); - } -}; - -var_dump(stream_register_filter("string.uppercase", "UpperCaseFilter")); -$fp = tmpfile(); - -fwrite($fp, "hello there"); -rewind($fp); - -var_dump(stream_filter_prepend($fp, "string.uppercase")); -var_dump(fgets($fp)); -fclose($fp); -?> ---EXPECT-- -bool(true) -oncreate: -string(16) "string.uppercase" -NULL -bool(true) -read: -read: -string(11) "HELLO THERE" -flush: -onclose: diff --git a/ext/standard/tests/file/userstreams.phpt b/ext/standard/tests/file/userstreams.phpt deleted file mode 100644 index efc2880f9a..0000000000 --- a/ext/standard/tests/file/userstreams.phpt +++ /dev/null @@ -1,325 +0,0 @@ ---TEST-- -User-space streams ---FILE-- -<?php -# vim600:syn=php: - -/* This is a fairly aggressive test that looks at - * user streams and also gives the seek/gets/buffer - * layer of streams a thorough testing */ - -$lyrics = <<<EOD -...and the road becomes my bride -I have stripped of all but pride -so in her I do confide -and she keeps me satisfied -gives me all I need -...and with dust in throat I crave -to the game you stay a slave -rover wanderer -nomad vagabond -call me what you will - But Ill take my time anywhere - Free to speak my mind anywhere - and Ill redefine anywhere - Anywhere I roam - Where I lay my head is home -...and the earth becomes my throne -I adapt to the unknown -under wandering stars Ive grown -by myself but not alone -I ask no one -...and my ties are severed clean -the less I have the more I gain -off the beaten path I reign -rover wanderer -nomad vagabond -call me what you will - But Ill take my time anywhere - Free to speak my mind anywhere - and Ill never mind anywhere - Anywhere I roam - Where I lay my head is home - But Ill take my time anywhere - Free to speak my mind anywhere - and Ill take my find anywhere - Anywhere I roam - Where I lay my head is home - carved upon my stone - my body lie but still I roam - Wherever I may roam. - -Wherever I May Roam - -EOD; - -/* repeat the data a few times so that it grows larger than - * the default cache chunk size and that we have something - * to seek around... */ -$DATA = ""; -for ($i = 0; $i < 30; $i++) { - if ($i % 2 == 0) - $DATA .= str_rot13($lyrics); - else - $DATA .= $lyrics; -} - -/* store the data in a regular file so that we can compare - * the results */ -$tf = tmpfile(); -fwrite($tf, $DATA); -$n = ftell($tf); -rewind($tf) or die("failed to rewind tmp file!"); -if (ftell($tf) != 0) - die("tmpfile is not at start!"); -$DATALEN = strlen($DATA); -if ($n != $DATALEN) - die("tmpfile stored $n bytes; should be $DATALEN!"); - -class uselessstream -{ -} - -class mystream -{ - var $path; - var $mode; - var $options; - - var $position; - var $varname; - - function stream_open($path, $mode, $options, &$opened_path) - { - $this->path = $path; - $this->mode = $mode; - $this->options = $options; - - $split = parse_url($path); - $this->varname = $split["host"]; - - if (strchr($mode, 'a')) - $this->position = strlen($GLOBALS[$this->varname]); - else - $this->position = 0; - - return true; - } - - function stream_read($count) - { - $ret = substr($GLOBALS[$this->varname], $this->position, $count); - $this->position += strlen($ret); - return $ret; - } - - function stream_tell() - { - return $this->position; - } - - function stream_eof() - { - return $this->position >= strlen($GLOBALS[$this->varname]); - } - - function stream_seek($offset, $whence) - { - switch($whence) { - case SEEK_SET: - if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) { - $this->position = $offset; - return true; - } else { - return false; - } - break; - case SEEK_CUR: - if ($offset >= 0) { - $this->position += $offset; - return true; - } else { - return false; - } - break; - case SEEK_END: - if (strlen($GLOBALS[$this->varname]) + $offset >= 0) { - $this->position = strlen($GLOBALS[$this->varname]) + $offset; - return true; - } else { - return false; - } - break; - default: - return false; - } - } - -} - -if (@stream_register_wrapper("bogus", "class_not_exist")) { - die("Registered a non-existant class!!!???"); -} -echo "Not Registered\n"; - -if (!stream_register_wrapper("test", "mystream")) { - die("test wrapper registration failed"); -} -echo "Registered\n"; - -if (!stream_register_wrapper("bogon", "uselessstream")) { - die("bogon wrapper registration failed"); -} -echo "Registered\n"; - -$b = @fopen("bogon://url", "rb"); -if (is_resource($b)) { - die("Opened a bogon??"); -} - -$fp = fopen("test://DATA", "rb"); -if (!$fp || !is_resource($fp)) { - die("Failed to open resource"); -} - -/* some default seeks that will cause buffer/cache misses */ -$seeks = array( - array(SEEK_SET, 0, 0), - array(SEEK_CUR, 8450, 8450), - array(SEEK_CUR, -7904, 546), - array(SEEK_CUR, 12456, 13002), - - /* end up at BOF so that randomly generated seek offsets - * below will know where they are supposed to be */ - array(SEEK_SET, 0, 0) -); - -$whence_map = array( - SEEK_CUR, - SEEK_SET, - SEEK_END -); -$whence_names = array( - SEEK_CUR => "SEEK_CUR", - SEEK_SET => "SEEK_SET", - SEEK_END => "SEEK_END" - ); - -/* generate some random seek offsets */ -$position = 0; -for ($i = 0; $i < 256; $i++) { - $whence = $whence_map[array_rand($whence_map, 1)]; - switch($whence) { - case SEEK_SET: - $offset = rand(0, $DATALEN); - $position = $offset; - break; - case SEEK_END: - $offset = -rand(0, $DATALEN); - $position = $DATALEN + $offset; - break; - case SEEK_CUR: - $offset = rand(0, $DATALEN); - $offset -= $position; - $position += $offset; - break; - } - - $seeks[] = array($whence, $offset, $position); -} - -/* we compare the results of fgets using differing line lengths to - * test the fgets layer also */ -$line_lengths = array(1024, 256, 64, 16); -$fail_count = 0; - -ob_start(); -foreach($line_lengths as $line_length) { - /* now compare the real stream with the user stream */ - $j = 0; - rewind($tf); - rewind($fp); - foreach($seeks as $seekdata) { - list($whence, $offset, $position) = $seekdata; - - $rpb = ftell($tf); - $rr = (int)fseek($tf, $offset, $whence); - $rpa = ftell($tf); - $rline = fgets($tf, $line_length); - (int)fseek($tf, - strlen($rline), SEEK_CUR); - - $upb = ftell($fp); - $ur = (int)fseek($fp, $offset, $whence); - $upa = ftell($fp); - $uline = fgets($fp, $line_length); - (int)fseek($fp, - strlen($uline), SEEK_CUR); - - printf("\n--[%d] whence=%s offset=%d line_length=%d position_should_be=%d --\n", - $j, $whence_names[$whence], $offset, $line_length, $position); - printf("REAL: pos=(%d,%d,%d) ret=%d line[%d]=`%s'\n", $rpb, $rpa, ftell($tf), $rr, strlen($rline), $rline); - printf("USER: pos=(%d,%d,%d) ret=%d line[%d]=`%s'\n", $upb, $upa, ftell($fp), $ur, strlen($uline), $uline); - - if ($rr != $ur || $rline != $uline || $rpa != $position || $upa != $position) { - $fail_count++; - echo "###################################### FAIL!\n"; - $dat = stream_get_meta_data($fp); - var_dump($dat); - break; - } - - $j++; - } - if ($fail_count) - break; -} - -if ($fail_count == 0) { - ob_end_clean(); - echo "SEEK: OK\n"; -} else { - echo "SEEK: FAIL\n"; - ob_end_flush(); -} - -$fail_count = 0; - -fseek($fp, $DATALEN / 2, SEEK_SET); -fseek($tf, $DATALEN / 2, SEEK_SET); - -if (ftell($fp) != ftell($tf)) { - echo "SEEK: positions do not match!\n"; -} - -$n = 0; -while(!feof($fp)) { - $uline = fgets($fp, 1024); - $rline = fgets($tf, 1024); - - if ($uline != $rline) { - echo "FGETS: FAIL\niter=$n user=$uline [pos=" . ftell($fp) . "]\nreal=$rline [pos=" . ftell($tf) . "]\n"; - $fail_count++; - break; - } -} - -if ($fail_count == 0) { - echo "FGETS: OK\n"; -} - -/* One final test to see if the position is respected when opened for append */ -$fp = fopen("test://lyrics", "a+"); -rewind($fp); -var_dump(ftell($fp)); -$data = fgets($fp); -fclose($fp); -echo $data . "\n"; - -?> ---EXPECT-- -Not Registered -Registered -Registered -SEEK: OK -FGETS: OK -int(0) -...and the road becomes my bride |
