Convert most of TestExtMisc to php; delete rest

Removed all the tests that tested functions that just throw
NotImplemented, or actually did sleeps (without any testing that the
sleep actually did anything).  Otherwise about the same, but I had to
add some assumptions in unpack because you can't do sizeof() from php.
Esse commit está contido em:
Jordan DeLong
2013-06-15 01:32:17 -07:00
commit de Sara Golemon
commit 877603b393
7 arquivos alterados com 107 adições e 337 exclusões
-1
Ver Arquivo
@@ -48,7 +48,6 @@
#include "hphp/test/ext/test_ext_mb.h"
#include "hphp/test/ext/test_ext_mcrypt.h"
#include "hphp/test/ext/test_ext_memcached.h"
#include "hphp/test/ext/test_ext_misc.h"
#include "hphp/test/ext/test_ext_mysql.h"
#include "hphp/test/ext/test_ext_network.h"
#include "hphp/test/ext/test_ext_openssl.h"
-275
Ver Arquivo
@@ -1,275 +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_misc.h"
#include "hphp/runtime/ext/ext_misc.h"
#include "hphp/runtime/ext/ext_string.h"
///////////////////////////////////////////////////////////////////////////////
bool TestExtMisc::RunTests(const std::string &which) {
bool ret = true;
DECLARE_TEST_FUNCTIONS("");
RUN_TEST(test_connection_aborted);
RUN_TEST(test_connection_status);
RUN_TEST(test_connection_timeout);
RUN_TEST(test_constant);
RUN_TEST(test_define);
RUN_TEST(test_defined);
RUN_TEST(test_die);
RUN_TEST(test_exit);
RUN_TEST(test_eval);
RUN_TEST(test_get_browser);
RUN_TEST(test___halt_compiler);
RUN_TEST(test_highlight_file);
RUN_TEST(test_show_source);
RUN_TEST(test_highlight_string);
RUN_TEST(test_ignore_user_abort);
RUN_TEST(test_pack);
RUN_TEST(test_php_check_syntax);
RUN_TEST(test_php_strip_whitespace);
RUN_TEST(test_sleep);
RUN_TEST(test_usleep);
RUN_TEST(test_time_nanosleep);
RUN_TEST(test_time_sleep_until);
RUN_TEST(test_uniqid);
RUN_TEST(test_unpack);
RUN_TEST(test_sys_getloadavg);
RUN_TEST(test_token_get_all);
RUN_TEST(test_token_name);
return ret;
}
///////////////////////////////////////////////////////////////////////////////
bool TestExtMisc::test_connection_aborted() {
VERIFY(!f_connection_aborted());
return Count(true);
}
bool TestExtMisc::test_connection_status() {
VERIFY(f_connection_status() == k_CONNECTION_NORMAL);
return Count(true);
}
bool TestExtMisc::test_connection_timeout() {
VERIFY(!f_connection_timeout());
return Count(true);
}
bool TestExtMisc::test_constant() {
f_constant("a");
return Count(true);
}
bool TestExtMisc::test_define() {
// a function that's never called
return Count(true);
}
bool TestExtMisc::test_defined() {
VERIFY(!f_defined("a"));
return Count(true);
}
bool TestExtMisc::test_die() {
// can't really test this
return Count(true);
}
bool TestExtMisc::test_exit() {
// can't really test this
return Count(true);
}
bool TestExtMisc::test_eval() {
try {
f_eval("sleep(5);");
} catch (const NotSupportedException& e) {
return Count(false);
}
return Count(true);
}
bool TestExtMisc::test_get_browser() {
try {
f_get_browser();
} catch (const NotSupportedException& e) {
return Count(true);
}
return Count(false);
}
bool TestExtMisc::test___halt_compiler() {
f___halt_compiler();
return Count(true);
}
bool TestExtMisc::test_highlight_file() {
try {
f_highlight_file("a");
} catch (const NotSupportedException& e) {
return Count(true);
}
return Count(false);
}
bool TestExtMisc::test_show_source() {
try {
f_show_source("a");
} catch (const NotSupportedException& e) {
return Count(true);
}
return Count(false);
}
bool TestExtMisc::test_highlight_string() {
try {
f_highlight_string("a");
} catch (const NotSupportedException& e) {
return Count(true);
}
return Count(false);
}
bool TestExtMisc::test_ignore_user_abort() {
f_ignore_user_abort("a");
return Count(true);
}
bool TestExtMisc::test_pack() {
// covered in TestCodeRun::TestExtMisc
return Count(true);
}
bool TestExtMisc::test_php_check_syntax() {
try {
f_php_check_syntax("a");
} catch (const NotSupportedException& e) {
return Count(true);
}
return Count(false);
}
bool TestExtMisc::test_php_strip_whitespace() {
try {
f_php_strip_whitespace("a");
} catch (const NotSupportedException& e) {
return Count(true);
}
return Count(false);
}
bool TestExtMisc::test_sleep() {
f_sleep(1);
return Count(true);
}
bool TestExtMisc::test_usleep() {
f_usleep(1);
return Count(true);
}
bool TestExtMisc::test_time_nanosleep() {
f_time_nanosleep(0, 100);
return Count(true);
}
bool TestExtMisc::test_time_sleep_until() {
struct timeval tm;
gettimeofday((struct timeval *)&tm, nullptr);
double timestamp = tm.tv_sec + tm.tv_usec / 1000000.0 + 2;
f_time_sleep_until(timestamp);
return Count(true);
}
bool TestExtMisc::test_uniqid() {
VERIFY(!f_uniqid().empty());
return Count(true);
}
#define VUNPACK(fmt, inp, exp) \
{ Array __a = f_unpack(fmt, inp); \
VS(__a.exists(1), true); \
VS(__a[1], (int64_t)exp); }
bool TestExtMisc::test_unpack() {
// Also covered in TestCodeRun::TestExtMisc
String iFF = f_str_repeat("\xFF", sizeof(int));
String le32_FF("\xFF\x00\x00\x00", 4, AttachLiteral);
String be32_FF("\x00\x00\x00\xFF", 4, AttachLiteral);
String le16_FF("\xFF\x00", 2, AttachLiteral);
String be16_FF("\x00\xFF", 2, AttachLiteral);
uint32_t endian_check = 1;
bool le = ((char*)&endian_check)[0];
// HPHP, unlike PHP, truncates overflowing ints
if (sizeof(int) == 8) {
VUNPACK("I", iFF, 0x7FFFFFFFFFFFFFFF);
} else if (sizeof(int) == 4) {
VUNPACK("I", iFF, 0xFFFFFFFF);
} else {
// Panic
VS(true, false);
}
VUNPACK("i", iFF, -1);
// LlNV test 32-bit ints specifically
VUNPACK("L", iFF, 0xFFFFFFFF);
VUNPACK("l", iFF, -1);
VUNPACK("N", be32_FF, 0xFF);
VUNPACK("V", le32_FF, 0xFF);
VUNPACK("V", be32_FF, 0xFF000000);
VUNPACK("L", le ? le32_FF : be32_FF, 0xFF);
// Ssnv test 16-bit shorts
VUNPACK("S", iFF, 0xFFFF);
VUNPACK("s", iFF, -1);
VUNPACK("n", be16_FF, 0xFF);
VUNPACK("v", le16_FF, 0xFF);
VUNPACK("v", be16_FF, 0xFF00);
VUNPACK("S", le ? le16_FF : be16_FF, 0xFF);
return Count(true);
}
bool TestExtMisc::test_sys_getloadavg() {
VERIFY(f_sys_getloadavg().size() == 3);
return Count(true);
}
bool TestExtMisc::test_token_get_all() {
String src = "blarb <?php 1";
VS(f_token_get_all(src),
CREATE_VECTOR3(CREATE_VECTOR3(k_T_INLINE_HTML, "blarb ", 1),
CREATE_VECTOR3(k_T_OPEN_TAG, "<?php ", 1),
CREATE_VECTOR3(k_T_LNUMBER, "1", 1)));
return Count(true);
}
bool TestExtMisc::test_token_name() {
VS(f_token_name(258), "T_REQUIRE_ONCE");
return Count(true);
}
-61
Ver Arquivo
@@ -1,61 +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_MISC_H_
#define incl_HPHP_TEST_EXT_MISC_H_
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
#include "hphp/test/ext/test_cpp_ext.h"
///////////////////////////////////////////////////////////////////////////////
class TestExtMisc : public TestCppExt {
public:
virtual bool RunTests(const std::string &which);
bool test_connection_aborted();
bool test_connection_status();
bool test_connection_timeout();
bool test_constant();
bool test_define();
bool test_defined();
bool test_die();
bool test_exit();
bool test_eval();
bool test_get_browser();
bool test___halt_compiler();
bool test_highlight_file();
bool test_show_source();
bool test_highlight_string();
bool test_ignore_user_abort();
bool test_pack();
bool test_php_check_syntax();
bool test_php_strip_whitespace();
bool test_sleep();
bool test_usleep();
bool test_time_nanosleep();
bool test_time_sleep_until();
bool test_uniqid();
bool test_unpack();
bool test_sys_getloadavg();
bool test_token_get_all();
bool test_token_name();
};
///////////////////////////////////////////////////////////////////////////////
#endif // incl_HPHP_TEST_EXT_MISC_H_
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<?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, true); }
//////////////////////////////////////////////////////////////////////
VERIFY(connection_aborted() != true);
VERIFY(connection_status() == CONNECTION_NORMAL);
VERIFY(connection_timeout() != true);
constant("a");
VERIFY(defined("a") != true);
__halt_compiler();
ignore_user_abort("a");
VERIFY(empty(uniqid()) != true);
VS(token_name(258), "T_REQUIRE_ONCE");
VS(count(sys_getloadavg()), 3);
$src = "blarb <?php 1";
VS(token_get_all(src),
array(array(T_INLINE_HTML, "blarb ", 1),
array(T_OPEN_TAG, "<?php", 1)));
@@ -0,0 +1,4 @@
bool(true)
bool(true)
bool(true)
bool(true)
+48
Ver Arquivo
@@ -0,0 +1,48 @@
<?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 VUNPACK($fmt, $inp, $exp) {
$a = unpack($fmt, $inp);
VS(isset($a[1]), true);
VS($a[1], (int)$exp);
}
function test_unpack() {
$iFF = str_repeat("\xFF", 4);
$le32_FF = "\xFF\x00\x00\x00";
$be32_FF = "\x00\x00\x00\xFF";
$le16_FF = "\xFF\x00";
$be16_FF = "\x00\xFF";
// HPHP, unlike PHP, truncates overflowing ints
VUNPACK("I", $iFF, 0xFFFFFFFF);
VUNPACK("i", $iFF, -1);
// LlNV test 32-bit ints specifically
VUNPACK("L", $iFF, 0xFFFFFFFF);
VUNPACK("l", $iFF, -1);
VUNPACK("N", $be32_FF, 0xFF);
VUNPACK("V", $le32_FF, 0xFF);
VUNPACK("V", $be32_FF, 0xFF000000);
VUNPACK("L", $le32_FF, 0xFF);
// Ssnv test 16-bit shorts
VUNPACK("S", $iFF, 0xFFFF);
VUNPACK("s", $iFF, -1);
VUNPACK("n", $be16_FF, 0xFF);
VUNPACK("v", $le16_FF, 0xFF);
VUNPACK("v", $be16_FF, 0xFF00);
VUNPACK("S", $le16_FF, 0xFF);
}
test_unpack();
+28
Ver Arquivo
@@ -0,0 +1,28 @@
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)