import bz2 tests

I had to edit ##bzopen## so that it handles file handles or else the test makes files called ##Resource #5## in the current directory.

The big problem with the broken tests is we return ##NULL## on too few args and Zend returns ##false##. I want to get a feel for other extensions before changing this.

I also imported ALL the files in the directory since the ##.phpt## files overflow.
Esse commit está contido em:
ptarjan
2013-04-06 18:03:09 -07:00
commit de Sara Golemon
commit 70a6d9cde9
30 arquivos alterados com 496 adições e 38 exclusões
+2 -2
Ver Arquivo
@@ -34,7 +34,7 @@
"args": [
{
"name": "filename",
"type": "String",
"type": "Variant",
"desc": "The name of the file to open."
},
{
@@ -226,4 +226,4 @@
],
"classes": [
]
}
}
+4
Ver Arquivo
@@ -30,6 +30,10 @@ BZ2File::BZ2File(): m_bzFile(nullptr), m_eof(false) {
m_innerFile->unregister();
}
BZ2File::BZ2File(PlainFile* innerFile): m_bzFile(nullptr), m_eof(false) {
m_innerFile = innerFile;
}
BZ2File::~BZ2File() {
if (m_bzFile)
closeImpl();
+1
Ver Arquivo
@@ -35,6 +35,7 @@ public:
CStrRef o_getClassNameHook() const { return s_class_name; }
BZ2File();
BZ2File(PlainFile* innerFile);
virtual ~BZ2File();
bool open(CStrRef filename, CStrRef mode);
+2
Ver Arquivo
@@ -121,6 +121,8 @@ public:
virtual Array getWrapperMetaData() { return null_array; }
virtual const char *getStreamType() const { return "";}
std::string getMode() { return m_mode; }
/**
* Read one line a time. Returns a null string on failure or eof.
*/
+53 -8
Ver Arquivo
@@ -34,19 +34,64 @@ Variant f_bzwrite(CObjRef bz, CStrRef data, int length /* = 0 */) {
return f_fwrite(bz, data, length);
}
Variant f_bzopen(CStrRef filename, CStrRef mode) {
Variant f_bzopen(CVarRef filename, CStrRef mode) {
if (mode != "r" && mode != "w") {
raise_warning(
"'%s' is not a valid mode for bzopen(). "
"Only 'w' and 'r' are supported.",
mode.data()
);
return false;
}
BZ2File *bz = NEWOBJ(BZ2File)();
BZ2File *bz;
if (filename.isString()) {
if (filename.asCStrRef().empty()) {
raise_warning("filename cannot be empty");
return false;
}
bz = NEWOBJ(BZ2File)();
bool ret = bz->open(File::TranslatePath(filename), mode);
if (!ret) {
raise_warning("%s", Util::safe_strerror(errno).c_str());
return false;
}
} else {
if (!filename.isResource()) {
raise_warning("first parameter has to be string or file-resource");
return false;
}
PlainFile* f = filename.cast<PlainFile>();
if (!f) {
return false;
}
std::string stream_mode = f->getMode();
int stream_mode_len = stream_mode.length();
if (stream_mode_len != 1 &&
!(stream_mode_len == 2 && stream_mode.find('b') != string::npos)) {
raise_warning("cannot use stream opened in mode '%s'", stream_mode.c_str());
return false;
} else if (stream_mode_len == 1 &&
stream_mode[0] != 'r' && stream_mode[0] != 'w' &&
stream_mode[0] != 'a' && stream_mode[0] != 'x') {
raise_warning("cannot use stream opened in mode '%s'", stream_mode.c_str());
return false;
}
const char rw_mode = stream_mode[0];
if (mode == "r" && rw_mode != 'r') {
raise_warning("cannot write to a stream opened in read only mode");
return false;
} else if (mode == "w" && rw_mode != 'w' && rw_mode != 'a' && rw_mode != 'x') {
raise_warning("cannot read from a stream opened in write only mode");
return false;
}
bz = NEWOBJ(BZ2File)(f);
}
Object handle(bz);
bool ret = bz->open(File::TranslatePath(filename), mode);
if (!ret) {
raise_warning("%s", Util::safe_strerror(errno).c_str());
return false;
}
return handle;
}
+7 -12
Ver Arquivo
@@ -75,8 +75,8 @@ TypedValue* fg_bzclose(HPHP::VM::ActRec *ar) {
/*
HPHP::Variant HPHP::f_bzopen(HPHP::String const&, HPHP::String const&)
_ZN4HPHP8f_bzopenERKNS_6StringES2_
HPHP::Variant HPHP::f_bzopen(HPHP::Variant const&, HPHP::String const&)
_ZN4HPHP8f_bzopenERKNS_7VariantERKNS_6StringE
(return value) => rax
_rv => rdi
@@ -84,18 +84,13 @@ filename => rsi
mode => rdx
*/
TypedValue* fh_bzopen(TypedValue* _rv, Value* filename, Value* mode) asm("_ZN4HPHP8f_bzopenERKNS_6StringES2_");
TypedValue* fh_bzopen(TypedValue* _rv, TypedValue* filename, Value* mode) asm("_ZN4HPHP8f_bzopenERKNS_7VariantERKNS_6StringE");
TypedValue * fg1_bzopen(TypedValue* rv, HPHP::VM::ActRec* ar, int64_t count) __attribute__((noinline,cold));
TypedValue * fg1_bzopen(TypedValue* rv, HPHP::VM::ActRec* ar, int64_t count) {
TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
if (!IS_STRING_TYPE((args-1)->m_type)) {
tvCastToStringInPlace(args-1);
}
if (!IS_STRING_TYPE((args-0)->m_type)) {
tvCastToStringInPlace(args-0);
}
fh_bzopen((rv), &args[-0].m_data, &args[-1].m_data);
tvCastToStringInPlace(args-1);
fh_bzopen((rv), (args-0), &args[-1].m_data);
if (rv->m_type == KindOfUninit) rv->m_type = KindOfNull;
return rv;
}
@@ -105,8 +100,8 @@ TypedValue* fg_bzopen(HPHP::VM::ActRec *ar) {
int64_t count = ar->numArgs();
TypedValue* args UNUSED = ((TypedValue*)ar) - 1;
if (count == 2LL) {
if (IS_STRING_TYPE((args-1)->m_type) && IS_STRING_TYPE((args-0)->m_type)) {
fh_bzopen((&(rv)), &args[-0].m_data, &args[-1].m_data);
if (IS_STRING_TYPE((args-1)->m_type)) {
fh_bzopen((&(rv)), (args-0), &args[-1].m_data);
if (rv.m_type == KindOfUninit) rv.m_type = KindOfNull;
frame_free_locals_no_this_inl(ar, 2);
memcpy(&ar->m_r, &rv, sizeof(TypedValue));
+3 -3
Ver Arquivo
@@ -28,8 +28,8 @@ bz => rsi
TypedValue* fh_bzclose(TypedValue* _rv, Value* bz) asm("_ZN4HPHP9f_bzcloseERKNS_6ObjectE");
/*
HPHP::Variant HPHP::f_bzopen(HPHP::String const&, HPHP::String const&)
_ZN4HPHP8f_bzopenERKNS_6StringES2_
HPHP::Variant HPHP::f_bzopen(HPHP::Variant const&, HPHP::String const&)
_ZN4HPHP8f_bzopenERKNS_7VariantERKNS_6StringE
(return value) => rax
_rv => rdi
@@ -37,7 +37,7 @@ filename => rsi
mode => rdx
*/
TypedValue* fh_bzopen(TypedValue* _rv, Value* filename, Value* mode) asm("_ZN4HPHP8f_bzopenERKNS_6StringES2_");
TypedValue* fh_bzopen(TypedValue* _rv, TypedValue* filename, Value* mode) asm("_ZN4HPHP8f_bzopenERKNS_7VariantERKNS_6StringE");
/*
HPHP::Variant HPHP::f_bzread(HPHP::Object const&, int)
+1 -1
Ver Arquivo
@@ -30,7 +30,7 @@ Variant f_bzclose(CObjRef bz);
Variant f_bzread(CObjRef bz, int length = 1024);
Variant f_bzwrite(CObjRef bz, CStrRef data, int length = 0);
Variant f_bzopen(CStrRef filename, CStrRef mode);
Variant f_bzopen(CVarRef filename, CStrRef mode);
Variant f_bzflush(CObjRef bz);
String f_bzerrstr(CObjRef bz);
Variant f_bzerror(CObjRef bz);
+2 -2
Ver Arquivo
@@ -12363,8 +12363,8 @@ const char *g_class_map[] = {
NULL,
NULL,
(const char *)0x10006040, "bzopen", "", (const char*)0, (const char*)0,
"/**\n * ( excerpt from http://php.net/manual/en/function.bzopen.php )\n *\n * bzopen() opens a bzip2 (.bz2) file for reading or writing.\n *\n * @filename string The name of the file to open.\n * @mode string Similar to the fopen() function, only 'r' (read) and\n * 'w' (write) are supported. Everything else will\n * cause bzopen to return FALSE.\n *\n * @return mixed If the open fails, bzopen() returns FALSE, otherwise\n * it returns a pointer to the newly opened file.\n */",
(const char *)0xffffffff /* KindOfUnknown: $t: Variant */, (const char *)0x2000, "filename", "", (const char *)0x14 /* KindOfString */, "", (const char *)0, "", (const char *)0, NULL,
"/**\n * ( excerpt from http://php.net/manual/en/function.bzopen.php )\n *\n * bzopen() opens a bzip2 (.bz2) file for reading or writing.\n *\n * @filename mixed The name of the file to open.\n * @mode string Similar to the fopen() function, only 'r' (read) and\n * 'w' (write) are supported. Everything else will\n * cause bzopen to return FALSE.\n *\n * @return mixed If the open fails, bzopen() returns FALSE, otherwise\n * it returns a pointer to the newly opened file.\n */",
(const char *)0xffffffff /* KindOfUnknown: $t: Variant */, (const char *)0x2000, "filename", "", (const char *)0xffffffff /* KindOfUnknown: $t: Variant */, "", (const char *)0, "", (const char *)0, NULL,
(const char *)0x2000, "mode", "", (const char *)0x14 /* KindOfString */, "", (const char *)0, "", (const char *)0, NULL,
NULL,
NULL,
+13
Ver Arquivo
@@ -0,0 +1,13 @@
<?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";
?>
+19
Ver Arquivo
@@ -0,0 +1,19 @@
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
string(0) ""
HipHop Warning: %a
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
+40
Ver Arquivo
@@ -0,0 +1,40 @@
<?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";
?>
+61
Ver Arquivo
@@ -0,0 +1,61 @@
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)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
Done
+34
Ver Arquivo
@@ -0,0 +1,34 @@
<?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";
?>
+29
Ver Arquivo
@@ -0,0 +1,29 @@
HipHop Warning: %a
NULL
string(%d) "BZ%a"
int(-2)
int(-2)
int(-2)
int(-2)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
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
@@ -0,0 +1,10 @@
<?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);
?>
@@ -0,0 +1 @@
QlpoNDFBWSZTWRN6QG0AAAoVgECFACA395UgIABIintI1N6mpowIQ0E1MTTAQGYTNcRyMZm5kgW3ib7hVboE7Tmqj3ToGZ5G3q1ZauD2G58hibSck8KS95EEAbx1Cn+LuSKcKEgJvSA2gA==
@@ -0,0 +1,10 @@
<?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);
?>
@@ -0,0 +1 @@
I am the very model of a modern major general, I've information vegetable, animal, and mineral.
+19
Ver Arquivo
@@ -0,0 +1,19 @@
<?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');
@@ -0,0 +1 @@
OK
+15
Ver Arquivo
@@ -0,0 +1,15 @@
<?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";
?>
+16
Ver Arquivo
@@ -0,0 +1,16 @@
HipHop Warning: %a
NULL
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
resource(%d) of type (stream)
Done
+70
Ver Arquivo
@@ -0,0 +1,70 @@
<?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";
?>
+37
Ver Arquivo
@@ -0,0 +1,37 @@
resource(%d) of type (stream)
resource(%d) of type (stream)
resource(%d) of type (stream)
HipHop Warning: %a
bool(false)
resource(%d) of type (stream)
resource(%d) of type (stream)
HipHop Warning: %a
HipHop Warning: %a
bool(false)
HipHop Warning: %a
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
HipHop Warning: %a
bool(false)
resource(%d) of type (stream)
Done
+16
Ver Arquivo
@@ -0,0 +1,16 @@
<?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);
@@ -0,0 +1 @@
This is a test string.
+15
Ver Arquivo
@@ -0,0 +1,15 @@
<?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);
@@ -0,0 +1 @@
This is a test string.
+12 -10
Ver Arquivo
@@ -111,6 +111,18 @@ def mkdir_p(path):
def walk(filename, source):
print "Importing %s" % filename
dest_filename = os.path.basename(filename).replace('.phpt', '.php')
source_dir = source.lower().replace('/tests', '').replace('/', '-')
cur_dir = os.path.dirname(__file__)
dest_subdir = os.path.join(cur_dir, '../test/zend/all', source_dir)
mkdir_p(dest_subdir)
full_dest_filename = os.path.join(dest_subdir, dest_filename)
if not '.phpt' in filename:
shutil.copyfile(filename, full_dest_filename)
return
def split(pattern, str):
return re.split(r'\n\s*--'+pattern+'--\s*\n', str, 1)
@@ -139,9 +151,6 @@ def walk(filename, source):
if not sections.has_key('FILE'):
print "Malformed test, no --FILE--: ", filename
return
dest_filename = os.path.basename(filename).replace('.phpt', '.php')
source_dir = source.lower().replace('/tests', '').replace('/', '-')
for key in ('EXPECT', 'EXPECTF', 'EXPECTREGEX'):
if sections.has_key(key):
@@ -170,11 +179,6 @@ def walk(filename, source):
sections[key] = exp
cur_dir = os.path.dirname(__file__)
dest_subdir = os.path.join(cur_dir, '../test/zend/all', source_dir)
mkdir_p(dest_subdir)
full_dest_filename = os.path.join(dest_subdir, dest_filename)
if sections.has_key('EXPECT'):
exp = sections['EXPECT']
# we use %a for error messages so always write expectf
@@ -287,8 +291,6 @@ if args.zend_path:
'/ext/xsl',
'/ext/zip',
)
if not '.phpt' in filename:
return False
for bad in no_import:
if bad in filename:
return False