Files
php-rar/tests/080.phpt
cataphract dff57d32cb - Implemented count elements handler for RarArchive.
- Fixed handling of archives with no entries.
- Removed trailing full stops from some error messages.
- Substituted zend_error for php_error_docref.
- Fixed inconsistent behavior of EOF for streams (reading at file boundaries would could set EOF or not).

git-svn-id: http://svn.php.net/repository/pecl/rar/trunk@299945 c90b9560-bf6c-de11-be94-00142212c4b1
2010-05-30 00:51:55 +00:00

110 lines
2.3 KiB
PHP

--TEST--
File stream EOF behavior
--SKIPIF--
<?php if(!extension_loaded("rar")) print "skip"; ?>
--FILE--
<?php
$a = RarArchive::open(dirname(__FILE__) . "/multi.part1.rar");
$a2 = RarArchive::open(dirname(__FILE__) . "/4mb.rar");
function echoeof($stream) {
echo feof($stream)?"At eof":"Not at eof";
echo "\n";
}
echo "* First fread is given file size:\n";
$stream = $a->getEntry("file1.txt")->getStream();
echoeof($stream);
var_dump(fread($stream, 18));
echoeof($stream);
var_dump(fread($stream, 1));
echoeof($stream);
echo "\n* First fread is given size - 1:\n";
$stream = $a->getEntry("file1.txt")->getStream();
echoeof($stream);
var_dump(fread($stream, 17));
echoeof($stream);
var_dump(fread($stream, 1));
echoeof($stream);
var_dump(fread($stream, 1));
echoeof($stream);
echo "\n* First fread is given size + 1:\n";
$stream = $a->getEntry("file1.txt")->getStream();
echoeof($stream);
var_dump(fread($stream, 19));
echoeof($stream);
echo "\n* Read is aligned with dictionary, buffer and file size:\n";
$stream = $a2->getEntry("4mb.txt")->getStream();
echoeof($stream);
var_dump(strlen(fread($stream, 4194304)));
echoeof($stream);
var_dump(strlen(fread($stream, 1)));
echoeof($stream);
echo "\n* Read is dictionary, buffer and file size - 1:\n";
$stream = $a2->getEntry("4mb.txt")->getStream();
echoeof($stream);
var_dump(strlen(fread($stream, 4194303)));
echoeof($stream);
var_dump(strlen(fread($stream, 1)));
echoeof($stream);
var_dump(strlen(fread($stream, 1)));
echoeof($stream);
echo "\n* Read is dictionary, buffer and file size + 1:\n";
$stream = $a2->getEntry("4mb.txt")->getStream();
echoeof($stream);
var_dump(strlen(fread($stream, 4194305)));
echoeof($stream);
echo "\n";
echo "Done.\n";
--EXPECTF--
* First fread is given file size:
Not at eof
string(18) "contents of file 1"
Not at eof
string(0) ""
At eof
* First fread is given size - 1:
Not at eof
string(17) "contents of file "
Not at eof
string(1) "1"
Not at eof
string(0) ""
At eof
* First fread is given size + 1:
Not at eof
string(18) "contents of file 1"
At eof
* Read is aligned with dictionary, buffer and file size:
Not at eof
int(4194304)
Not at eof
int(0)
At eof
* Read is dictionary, buffer and file size - 1:
Not at eof
int(4194303)
Not at eof
int(1)
Not at eof
int(0)
At eof
* Read is dictionary, buffer and file size + 1:
Not at eof
int(4194304)
At eof
Done.