This source file includes following definitions.
- CaptureErrorCallback
- SetUp
- TearDown
- db
- TEST_F
- TEST_F
- TEST_F
#include <string>
#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "sql/connection.h"
#include "sql/statement.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
namespace {
void CaptureErrorCallback(int* error_pointer, std::string* sql_text,
int error, sql::Statement* stmt) {
*error_pointer = error;
const char* text = stmt ? stmt->GetSQLStatement() : NULL;
*sql_text = text ? text : "no statement available";
}
class SQLiteFeaturesTest : public testing::Test {
public:
SQLiteFeaturesTest() : error_(SQLITE_OK) {}
virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
db_.set_error_callback(base::Bind(&CaptureErrorCallback,
&error_, &sql_text_));
}
virtual void TearDown() {
EXPECT_EQ(SQLITE_OK, error_);
db_.Close();
}
sql::Connection& db() { return db_; }
private:
base::ScopedTempDir temp_dir_;
sql::Connection db_;
int error_;
std::string sql_text_;
};
TEST_F(SQLiteFeaturesTest, NoFTS1) {
ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode(
"CREATE VIRTUAL TABLE foo USING fts1(x)"));
}
#if !defined(OS_IOS)
TEST_F(SQLiteFeaturesTest, FTS2) {
ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)"));
}
#endif
TEST_F(SQLiteFeaturesTest, FTS3) {
ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
}
}