From 2147b113348e06c61d87cf37590a9268eefd251a Mon Sep 17 00:00:00 2001 From: Jordan DeLong Date: Sun, 16 Jun 2013 13:52:14 -0700 Subject: [PATCH] TestExtSqlite3 -> php Except part of it that SEGVs in the JIT. (See task.) --- hphp/test/ext/test_ext.h | 1 - hphp/test/ext/test_ext_sqlite3.cpp | 137 ------------------ hphp/test/ext/test_ext_sqlite3.h | 37 ----- hphp/test/slow/ext_sqlite3/ext_sqlite3.php | 92 ++++++++++++ .../slow/ext_sqlite3/ext_sqlite3.php.expect | 21 +++ 5 files changed, 113 insertions(+), 175 deletions(-) delete mode 100644 hphp/test/ext/test_ext_sqlite3.cpp delete mode 100644 hphp/test/ext/test_ext_sqlite3.h create mode 100644 hphp/test/slow/ext_sqlite3/ext_sqlite3.php create mode 100644 hphp/test/slow/ext_sqlite3/ext_sqlite3.php.expect diff --git a/hphp/test/ext/test_ext.h b/hphp/test/ext/test_ext.h index a93cb5b88..f07c2354c 100644 --- a/hphp/test/ext/test_ext.h +++ b/hphp/test/ext/test_ext.h @@ -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_ diff --git a/hphp/test/ext/test_ext_sqlite3.cpp b/hphp/test/ext/test_ext_sqlite3.cpp deleted file mode 100644 index 5fced8eed..000000000 --- a/hphp/test/ext/test_ext_sqlite3.cpp +++ /dev/null @@ -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(); - - 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(); - 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(); - 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(); - 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(); - 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(); - 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); -} diff --git a/hphp/test/ext/test_ext_sqlite3.h b/hphp/test/ext/test_ext_sqlite3.h deleted file mode 100644 index 7211af99a..000000000 --- a/hphp/test/ext/test_ext_sqlite3.h +++ /dev/null @@ -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_ diff --git a/hphp/test/slow/ext_sqlite3/ext_sqlite3.php b/hphp/test/slow/ext_sqlite3/ext_sqlite3.php new file mode 100644 index 000000000..3937a1bb0 --- /dev/null +++ b/hphp/test/slow/ext_sqlite3/ext_sqlite3.php @@ -0,0 +1,92 @@ +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"); diff --git a/hphp/test/slow/ext_sqlite3/ext_sqlite3.php.expect b/hphp/test/slow/ext_sqlite3/ext_sqlite3.php.expect new file mode 100644 index 000000000..c98b81343 --- /dev/null +++ b/hphp/test/slow/ext_sqlite3/ext_sqlite3.php.expect @@ -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)