Port TestExtZlib to php
Also fixed the memory leak.
Esse commit está contido em:
@@ -44,6 +44,5 @@
|
||||
#include "hphp/test/ext/test_ext_process.h"
|
||||
#include "hphp/test/ext/test_ext_server.h"
|
||||
#include "hphp/test/ext/test_ext_session.h"
|
||||
#include "hphp/test/ext/test_ext_zlib.h"
|
||||
|
||||
#endif // incl_EXT_LIST_TEST_EXT_H_
|
||||
|
||||
@@ -1,330 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#include "hphp/test/ext/test_ext_zlib.h"
|
||||
#include "hphp/runtime/ext/ext_zlib.h"
|
||||
#include "hphp/runtime/ext/ext_file.h"
|
||||
#include "hphp/runtime/ext/ext_output.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtZlib::RunTests(const std::string &which) {
|
||||
bool ret = true;
|
||||
|
||||
RUN_TEST(test_readgzfile);
|
||||
RUN_TEST(test_gzfile);
|
||||
RUN_TEST(test_gzcompress);
|
||||
RUN_TEST(test_gzuncompress);
|
||||
RUN_TEST(test_gzdeflate);
|
||||
RUN_TEST(test_gzinflate);
|
||||
RUN_TEST(test_gzencode);
|
||||
RUN_TEST(test_gzdecode);
|
||||
RUN_TEST(test_zlib_get_coding_type);
|
||||
RUN_TEST(test_gzopen);
|
||||
RUN_TEST(test_gzclose);
|
||||
RUN_TEST(test_gzrewind);
|
||||
RUN_TEST(test_gzeof);
|
||||
RUN_TEST(test_gzgetc);
|
||||
RUN_TEST(test_gzgets);
|
||||
RUN_TEST(test_gzgetss);
|
||||
RUN_TEST(test_gzread);
|
||||
RUN_TEST(test_gzpassthru);
|
||||
RUN_TEST(test_gzseek);
|
||||
RUN_TEST(test_gztell);
|
||||
RUN_TEST(test_gzwrite);
|
||||
RUN_TEST(test_gzputs);
|
||||
RUN_TEST(test_qlzcompress);
|
||||
RUN_TEST(test_qlzuncompress);
|
||||
RUN_TEST(test_sncompress);
|
||||
RUN_TEST(test_snuncompress);
|
||||
RUN_TEST(test_nzcompress);
|
||||
RUN_TEST(test_nzuncompress);
|
||||
RUN_TEST(test_lz4compress);
|
||||
RUN_TEST(test_lz4hccompress);
|
||||
RUN_TEST(test_lz4uncompress);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtZlib::test_readgzfile() {
|
||||
f_ob_start();
|
||||
f_readgzfile("test/ext/test_ext_zlib.gz");
|
||||
VS(f_ob_get_clean(), "Testing Ext Zlib\n");
|
||||
f_ob_end_clean();
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzfile() {
|
||||
VS(f_gzfile("test/ext/test_ext_zlib.gz"), CREATE_VECTOR1("Testing Ext Zlib\n"));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzcompress() {
|
||||
VS(f_gzuncompress(f_gzcompress("testing gzcompress")), "testing gzcompress");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzuncompress() {
|
||||
// tested in gzcompress
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzdeflate() {
|
||||
VS(f_gzinflate(f_gzdeflate("testing gzdeflate")), "testing gzdeflate");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzinflate() {
|
||||
// tested in gzdeflate
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzencode() {
|
||||
Variant zipped = f_gzencode("testing gzencode");
|
||||
Variant f = f_fopen("test/ext/test_ext_zlib.tmp", "w");
|
||||
f_fwrite(f, zipped);
|
||||
f_fclose(f);
|
||||
|
||||
f_ob_start();
|
||||
f_readgzfile("test/ext/test_ext_zlib.tmp");
|
||||
VS(f_ob_get_clean(), "testing gzencode");
|
||||
f_ob_end_clean();
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzdecode() {
|
||||
Variant zipped = f_gzencode("testing gzencode");
|
||||
VS(f_gzdecode(zipped), "testing gzencode");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_zlib_get_coding_type() {
|
||||
try {
|
||||
f_zlib_get_coding_type();
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzopen() {
|
||||
Variant f = f_gzopen("test/ext/test_ext_zlib.tmp", "w");
|
||||
VERIFY(!same(f, false));
|
||||
f_gzputs(f, "testing gzputs\n");
|
||||
f_gzwrite(f, "<html>testing gzwrite</html>\n");
|
||||
f_gzclose(f);
|
||||
|
||||
f = f_gzopen("test/ext/test_ext_zlib.tmp", "r");
|
||||
VS(f_gzread(f, 7), "testing");
|
||||
VS(f_gzgetc(f), " ");
|
||||
VS(f_gzgets(f), "gzputs\n");
|
||||
VS(f_gzgetss(f), "testing gzwrite\n");
|
||||
VS(f_gztell(f), 44);
|
||||
VERIFY(f_gzeof(f));
|
||||
VERIFY(f_gzrewind(f));
|
||||
VS(f_gztell(f), 0);
|
||||
VERIFY(!f_gzeof(f));
|
||||
f_gzseek(f, -7, k_SEEK_END);
|
||||
VS(f_gzgets(f), "testing gzputs\n");
|
||||
f_gzclose(f);
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzclose() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzrewind() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzeof() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzgetc() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzgets() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzgetss() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzread() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzpassthru() {
|
||||
Variant f = f_gzopen("test/ext/test_ext_zlib.gz", "r");
|
||||
f_ob_start();
|
||||
f_gzpassthru(f);
|
||||
VS(f_ob_get_clean(), "Testing Ext Zlib\n");
|
||||
f_ob_end_clean();
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzseek() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gztell() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzwrite() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_gzputs() {
|
||||
// tested in gzopen
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_qlzcompress() {
|
||||
// tested in test_qlzuncompress();
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_qlzuncompress() {
|
||||
try {
|
||||
VS(f_qlzuncompress(f_qlzcompress("testing gzcompress", 1), 1),
|
||||
"testing gzcompress");
|
||||
VS(f_qlzuncompress(f_qlzcompress("testing gzcompress", 2), 2),
|
||||
"testing gzcompress");
|
||||
VS(f_qlzuncompress(f_qlzcompress("testing gzcompress", 3), 3),
|
||||
"testing gzcompress");
|
||||
} catch (const NotSupportedException& e) {
|
||||
SKIP("no qlzcompress() support");
|
||||
}
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_sncompress() {
|
||||
// tested in test_sncompress();
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_snuncompress() {
|
||||
try {
|
||||
VS(f_snuncompress(f_sncompress("testing sncompress")),
|
||||
"testing sncompress");
|
||||
} catch (const NotSupportedException& e) {
|
||||
SKIP("No sncompress() support");
|
||||
}
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_nzcompress() {
|
||||
char compressable[1025];
|
||||
memset(compressable, 'A', 1024);
|
||||
compressable[1024] = '\0';
|
||||
String s(compressable, CopyString);
|
||||
String t(f_nzcompress(s).asStrRef());
|
||||
if (s.size() <= t.size()) {
|
||||
return Count(false);
|
||||
}
|
||||
String u(f_nzuncompress(t).asStrRef());
|
||||
if (s != u) {
|
||||
return Count(false);
|
||||
}
|
||||
char *p = (char*)malloc(t.size());
|
||||
if (p == nullptr) {
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
memset(compressable, '\0', 1025);
|
||||
String bs(compressable, 1024, CopyString);
|
||||
String bt(f_nzcompress(bs).asStrRef());
|
||||
if (bs.size() <= bt.size()) {
|
||||
return Count(false);
|
||||
}
|
||||
String bu(f_nzuncompress(bt).asStrRef());
|
||||
if (bu != bs || bu.size() != 1024) {
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_nzuncompress() {
|
||||
String s("garbage stuff", AttachLiteral);
|
||||
Variant v = f_nzuncompress(s);
|
||||
if (!equal(v, Variant(false))) {
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
String empty("", AttachLiteral);
|
||||
String c(f_nzcompress(empty).asStrRef());
|
||||
String d(f_nzuncompress(c).asStrRef());
|
||||
if (d != empty) {
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_lz4compress() {
|
||||
VS(f_lz4uncompress(f_lz4compress("testing lz4compress")),
|
||||
"testing lz4compress");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_lz4hccompress() {
|
||||
VS(f_lz4uncompress(f_lz4hccompress("testing lz4hccompress")),
|
||||
"testing lz4hccompress");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_lz4uncompress() {
|
||||
// first test uncompressing invalid string
|
||||
String s("invalid compressed string", AttachLiteral);
|
||||
Variant v = f_lz4uncompress(s);
|
||||
if (!equal(v, Variant(false))) {
|
||||
return Count(false);
|
||||
}
|
||||
// try uncompressing empty string
|
||||
String empty("", AttachLiteral);
|
||||
v = f_lz4uncompress(empty);
|
||||
if (!equal(v, Variant(false))) {
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
// compress and uncompress empty string
|
||||
String c(f_lz4compress(empty).asStrRef());
|
||||
String d(f_lz4uncompress(c).asStrRef());
|
||||
if (d != empty) {
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef incl_HPHP_TEST_EXT_ZLIB_H_
|
||||
#define incl_HPHP_TEST_EXT_ZLIB_H_
|
||||
|
||||
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
|
||||
|
||||
#include "hphp/test/ext/test_cpp_ext.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TestExtZlib : public TestCppExt {
|
||||
public:
|
||||
virtual bool RunTests(const std::string &which);
|
||||
|
||||
bool test_readgzfile();
|
||||
bool test_gzfile();
|
||||
bool test_gzcompress();
|
||||
bool test_gzuncompress();
|
||||
bool test_gzdeflate();
|
||||
bool test_gzinflate();
|
||||
bool test_gzencode();
|
||||
bool test_gzdecode();
|
||||
bool test_zlib_get_coding_type();
|
||||
bool test_gzopen();
|
||||
bool test_gzclose();
|
||||
bool test_gzrewind();
|
||||
bool test_gzeof();
|
||||
bool test_gzgetc();
|
||||
bool test_gzgets();
|
||||
bool test_gzgetss();
|
||||
bool test_gzread();
|
||||
bool test_gzpassthru();
|
||||
bool test_gzseek();
|
||||
bool test_gztell();
|
||||
bool test_gzwrite();
|
||||
bool test_gzputs();
|
||||
bool test_qlzcompress();
|
||||
bool test_qlzuncompress();
|
||||
bool test_sncompress();
|
||||
bool test_snuncompress();
|
||||
bool test_nzcompress();
|
||||
bool test_nzuncompress();
|
||||
bool test_lz4compress();
|
||||
bool test_lz4hccompress();
|
||||
bool test_lz4uncompress();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // incl_HPHP_TEST_EXT_ZLIB_H_
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
function VS($x, $y) {
|
||||
var_dump($x === $y);
|
||||
if ($x !== $y) { echo "Failed: $y\n"; echo "Got: $x\n";
|
||||
var_dump(debug_backtrace()); }
|
||||
}
|
||||
function VERIFY($x) { VS($x != false, true); }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
var_dump(readgzfile(__DIR__."/test_ext_zlib.gz"));
|
||||
|
||||
VS(gzfile(__DIR__."/test_ext_zlib.gz"), array("Testing Ext Zlib\n"));
|
||||
|
||||
VS(gzuncompress(gzcompress("testing gzcompress")), "testing gzcompress");
|
||||
|
||||
VS(gzinflate(gzdeflate("testing gzdeflate")), "testing gzdeflate");
|
||||
|
||||
$zipped = gzencode("testing gzencode");
|
||||
$tmpfile = tempnam('/tmp', 'vmzlibtest');
|
||||
$f = fopen($tmpfile, "w");
|
||||
fwrite($f, $zipped);
|
||||
fclose($f);
|
||||
|
||||
var_dump(readgzfile($tmpfile));
|
||||
|
||||
$zipped = gzencode("testing gzencode");
|
||||
VS(gzdecode($zipped), "testing gzencode");
|
||||
|
||||
|
||||
$f = gzopen($tmpfile, "w");
|
||||
VERIFY($f !== false);
|
||||
gzputs($f, "testing gzputs\n");
|
||||
gzwrite($f, "<html>testing gzwrite</html>\n");
|
||||
gzclose($f);
|
||||
|
||||
$f = gzopen($tmpfile, "r");
|
||||
VS(gzread($f, 7), "testing");
|
||||
VS(gzgetc($f), " ");
|
||||
VS(gzgets($f), "gzputs\n");
|
||||
VS(gzgetss($f), "testing gzwrite\n");
|
||||
VS(gztell($f), 44);
|
||||
VERIFY(gzeof($f));
|
||||
VERIFY(gzrewind($f));
|
||||
VS(gztell($f), 0);
|
||||
VERIFY(!gzeof($f));
|
||||
gzseek($f, -7, SEEK_END);
|
||||
VS(gzgets($f), "testing gzputs\n");
|
||||
gzclose($f);
|
||||
|
||||
$f = gzopen(__DIR__."/test_ext_zlib.gz", "r");
|
||||
gzpassthru($f);
|
||||
|
||||
$compressable = str_repeat('A', 1024);
|
||||
$s = $compressable;
|
||||
$t = nzcompress($s);
|
||||
|
||||
VERIFY(strlen($t) < strlen($s));
|
||||
|
||||
$u = nzuncompress($t);
|
||||
VS($u, $s);
|
||||
|
||||
$compressable = str_repeat('\0', 1024);
|
||||
$bs = $compressable;
|
||||
$bt = nzcompress($bs);
|
||||
VERIFY(strlen($bt) < strlen($bs));
|
||||
$bu = nzuncompress($bt);
|
||||
VS($bu, $bs);
|
||||
VS(count($bu), count($bs));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
$s = "garbage stuff";
|
||||
$v = nzuncompress($s);
|
||||
VERIFY($v == false);
|
||||
|
||||
$empty = "";
|
||||
$c = nzcompress($empty);
|
||||
$d = nzuncompress($c);
|
||||
VERIFY($d == $empty);
|
||||
|
||||
VS(lz4uncompress(lz4compress("testing lz4compress")),
|
||||
"testing lz4compress");
|
||||
|
||||
VS(lz4uncompress(lz4hccompress("testing lz4hccompress")),
|
||||
"testing lz4hccompress");
|
||||
|
||||
// first test uncompressing invalid string
|
||||
$s = "invalid compressed string";
|
||||
$v = lz4uncompress($s);
|
||||
VERIFY($v == false);
|
||||
|
||||
// try uncompressing empty string
|
||||
$empty = "";
|
||||
$v = lz4uncompress($empty);
|
||||
VERIFY($v == false);
|
||||
|
||||
$c = lz4compress($empty);
|
||||
$d = lz4uncompress($c);
|
||||
VERIFY($d == $empty);
|
||||
@@ -0,0 +1,31 @@
|
||||
Testing Ext Zlib
|
||||
int(17)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
testing gzencodeint(16)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
Testing Ext Zlib
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
Referência em uma Nova Issue
Bloquear um usuário