TestExtSqlite3 -> php

Except part of it that SEGVs in the JIT.  (See task.)
Esse commit está contido em:
Jordan DeLong
2013-06-16 13:52:14 -07:00
commit de Sara Golemon
commit 2147b11334
5 arquivos alterados com 113 adições e 175 exclusões
-1
Ver Arquivo
@@ -47,7 +47,6 @@
#include "hphp/test/ext/test_ext_server.h"
#include "hphp/test/ext/test_ext_session.h"
#include "hphp/test/ext/test_ext_soap.h"
#include "hphp/test/ext/test_ext_sqlite3.h"
#include "hphp/test/ext/test_ext_zlib.h"
#endif // incl_EXT_LIST_TEST_EXT_H_
-137
Ver Arquivo
@@ -1,137 +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_sqlite3.h"
#include "hphp/runtime/ext/ext_sqlite3.h"
#include "hphp/runtime/ext/ext_file.h"
///////////////////////////////////////////////////////////////////////////////
bool TestExtSqlite3::RunTests(const std::string &which) {
bool ret = true;
DECLARE_TEST_FUNCTIONS("function lower($a) {"
" return strtolower($a);"
"}"
"function sumlen_step($a,$b,$c) {"
" return (int)$a + strlen($c);"
"}"
"function sumlen_fini($a) {"
" return (int)$a;"
"}");
RUN_TEST(test_sqlite3);
RUN_TEST(test_sqlite3stmt);
RUN_TEST(test_sqlite3result);
return ret;
}
///////////////////////////////////////////////////////////////////////////////
bool TestExtSqlite3::test_sqlite3() {
p_SQLite3 db(NEWOBJ(c_SQLite3)());
db->t_open(":memory:test");
db->t_exec("DROP TABLE IF EXISTS foo");
db->t_exec("CREATE TABLE foo (bar STRING)");
db->t_exec("INSERT INTO foo VALUES ('ABC')");
db->t_exec("INSERT INTO foo VALUES ('DEF')");
VS(db->t_lastinsertrowid(), 2);
VS(db->t_changes(), 1);
VS(db->t_lasterrorcode(), 0);
VS(db->t_lasterrormsg(), "not an error");
VS(db->t_escapestring("'\""), "''\"");
VS(db->t_querysingle("SELECT * FROM foo"), "ABC");
VS(db->t_querysingle("SELECT * FROM foo", true), CREATE_MAP1("bar", "ABC"));
// testing query() and SQLite3Result
{
Object objResult = db->t_query("SELECT * FROM foo").toObject();
c_SQLite3Result *res = objResult.getTyped<c_SQLite3Result>();
VS(res->t_fetcharray(), CREATE_MAP2(0, "ABC", "bar", "ABC"));
VS(res->t_numcolumns(), 1);
VS(res->t_columnname(0), "bar");
VS(res->t_columntype(0), k_SQLITE3_TEXT);
VS(res->t_fetcharray(k_SQLITE3_NUM), CREATE_VECTOR1("DEF"));
}
// testing prepare() and sqlite3stmt
{
Object objStmt = db->t_prepare("SELECT * FROM foo WHERE bar = :id");
c_SQLite3Stmt *stmt = objStmt.getTyped<c_SQLite3Stmt>();
VS(stmt->t_paramcount(), 1);
Variant id = "DEF";
VERIFY(stmt->t_bindvalue(":id", id, SQLITE3_TEXT));
id = String("ABC");
{
Object objResult = stmt->t_execute();
c_SQLite3Result *res = objResult.getTyped<c_SQLite3Result>();
VS(res->t_fetcharray(k_SQLITE3_NUM), CREATE_VECTOR1("DEF"));
}
VERIFY(stmt->t_clear());
VERIFY(stmt->t_reset());
id = String("DEF");
VERIFY(stmt->t_bindparam(":id", ref(id), SQLITE3_TEXT));
id = String("ABC");
{
Object objResult = stmt->t_execute();
c_SQLite3Result *res = objResult.getTyped<c_SQLite3Result>();
VS(res->t_fetcharray(k_SQLITE3_NUM), CREATE_VECTOR1("ABC"));
}
}
// testing UDF
{
VERIFY(db->t_createfunction("tolower", "lower", 1));
Object objResult = db->t_query("SELECT tolower(bar) FROM foo").toObject();
c_SQLite3Result *res = objResult.getTyped<c_SQLite3Result>();
VS(res->t_fetcharray(k_SQLITE3_NUM), CREATE_VECTOR1("abc"));
}
{
VERIFY(db->t_createaggregate("sumlen", "sumlen_step", "sumlen_fini", 1));
Object objResult = db->t_query("SELECT sumlen(bar) FROM foo").toObject();
c_SQLite3Result *res = objResult.getTyped<c_SQLite3Result>();
VS(res->t_fetcharray(k_SQLITE3_NUM), CREATE_VECTOR1(6));
}
db->t_close();
static const StaticString s_versionString("versionString");
static const StaticString s_versionNumber("versionNumber");
// Since minor version can change frequently, just test the major version
VS(db->t_version()[s_versionString][0], "3");
VERIFY((int64_t)db->t_version()[s_versionNumber] >
(int64_t)3000000);
f_unlink(":memory:test");
return Count(true);
}
bool TestExtSqlite3::test_sqlite3stmt() {
// tested in test_sqlite3()
return Count(true);
}
bool TestExtSqlite3::test_sqlite3result() {
// tested in test_sqlite3()
return Count(true);
}
-37
Ver Arquivo
@@ -1,37 +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_SQLITE3_H_
#define incl_HPHP_TEST_EXT_SQLITE3_H_
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
#include "hphp/test/ext/test_cpp_ext.h"
///////////////////////////////////////////////////////////////////////////////
class TestExtSqlite3 : public TestCppExt {
public:
virtual bool RunTests(const std::string &which);
bool test_sqlite3();
bool test_sqlite3stmt();
bool test_sqlite3result();
};
///////////////////////////////////////////////////////////////////////////////
#endif // incl_HPHP_TEST_EXT_SQLITE3_H_
+92
Ver Arquivo
@@ -0,0 +1,92 @@
<?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); }
//////////////////////////////////////////////////////////////////////
function lower($a) {
return strtolower($a);
}
function sumlen_step($a,$b,$c) {
return (int)$a + strlen($c);
}
function sumlen_fini($a) {
return (int)$a;
}
$db = new SQLite3(':memory:');
//$db->open(":memory:test");
$db->exec("DROP TABLE IF EXISTS foo");
$db->exec("CREATE TABLE foo (bar STRING)");
$db->exec("INSERT INTO foo VALUES ('ABC')");
$db->exec("INSERT INTO foo VALUES ('DEF')");
VS($db->lastinsertrowid(), 2);
VS($db->changes(), 1);
VS($db->lasterrorcode(), 0);
VS($db->lasterrormsg(), "not an error");
VS($db->escapestring("'\""), "''\"");
VS($db->querysingle("SELECT * FROM foo"), "ABC");
VS($db->querysingle("SELECT * FROM foo", true), array("bar" => "ABC"));
// testing query() and SQLite3Result
{
$res = $db->query("SELECT * FROM foo");
VS($res->fetcharray(), array(0 => "ABC", "bar" => "ABC"));
VS($res->numcolumns(), 1);
VS($res->columnname(0), "bar");
VS($res->columntype(0), SQLITE3_TEXT);
VS($res->fetcharray(SQLITE3_NUM), array("DEF"));
}
// testing prepare() and sqlite3stmt
{
$stmt = $db->prepare("SELECT * FROM foo WHERE bar = :id");
VS($stmt->paramcount(), 1);
$id = "DEF";
VERIFY($stmt->bindvalue(":id", $id, SQLITE3_TEXT));
$id = "ABC";
{
$res = $stmt->execute();
VS($res->fetcharray(SQLITE3_NUM), array("DEF"));
}
VERIFY($stmt->clear());
VERIFY($stmt->reset());
$id = "DEF";
VERIFY($stmt->bindparam(":id", $id, SQLITE3_TEXT));
$id = "ABC";
{
$res = $stmt->execute();
VS($res->fetcharray(SQLITE3_NUM), array("ABC"));
}
}
// testing UDF
// TODO(#2512701): broken under the JIT compiler
{
//VERIFY($db->createfunction("tolower", "lower", 1));
//$res = $db->query("SELECT tolower(bar) FROM foo");
//VS($res->fetcharray(SQLITE3_NUM), array("abc"));
}
{
// VERIFY($db->createaggregate("sumlen", "sumlen_step", "sumlen_fini", 1));
// $res = $db->query("SELECT sumlen(bar) FROM foo");
// VS($res->fetcharray(SQLITE3_NUM), array(6));
}
$db->close();
// Since minor version can change frequently, just test the major version
VS($db->version()['versionString'][0], "3");
VERIFY((int)$db->version()['versionNumber'] > (int)3000000);
unlink(":memory:test");
@@ -0,0 +1,21 @@
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)