ash: Update launcher background to 0.8 black.
[chromium-blink-merge.git] / sql / sqlite_features_unittest.cc
blobd3ad7b01e1e9b00bb6e702c33518dad8d10f86ed
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
7 #include "base/file_util.h"
8 #include "base/scoped_temp_dir.h"
9 #include "sql/connection.h"
10 #include "sql/statement.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/sqlite/sqlite3.h"
14 // Test that certain features are/are-not enabled in our SQLite.
16 namespace {
19 class StatementErrorHandler : public sql::ErrorDelegate {
20 public:
21 StatementErrorHandler() : error_(SQLITE_OK) {}
23 virtual int OnError(int error, sql::Connection* connection,
24 sql::Statement* stmt) OVERRIDE {
25 error_ = error;
26 const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL;
27 sql_text_ = sql_txt ? sql_txt : "no statement available";
28 return error;
31 int error() const { return error_; }
33 void reset_error() {
34 sql_text_.clear();
35 error_ = SQLITE_OK;
38 const char* sql_statement() const { return sql_text_.c_str(); }
40 protected:
41 virtual ~StatementErrorHandler() {}
43 private:
44 int error_;
45 std::string sql_text_;
48 class SQLiteFeaturesTest : public testing::Test {
49 public:
50 SQLiteFeaturesTest() : error_handler_(new StatementErrorHandler) {}
52 void SetUp() {
53 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
54 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
56 // The |error_handler_| will be called if any sqlite statement operation
57 // returns an error code.
58 db_.set_error_delegate(error_handler_);
61 void TearDown() {
62 // If any error happened the original sql statement can be found in
63 // error_handler_->sql_statement().
64 EXPECT_EQ(SQLITE_OK, error_handler_->error());
65 db_.Close();
68 sql::Connection& db() { return db_; }
70 int sqlite_error() const { return error_handler_->error(); }
71 void reset_error() const { error_handler_->reset_error(); }
73 private:
74 ScopedTempDir temp_dir_;
75 sql::Connection db_;
76 scoped_refptr<StatementErrorHandler> error_handler_;
79 // Do not include fts1 support, it is not useful, and nobody is
80 // looking at it.
81 TEST_F(SQLiteFeaturesTest, NoFTS1) {
82 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode(
83 "CREATE VIRTUAL TABLE foo USING fts1(x)"));
86 #if !defined(OS_IOS)
87 // fts2 is used for older history files, so we're signed on for keeping our
88 // version up-to-date. iOS does not include fts2, so this test does not run on
89 // iOS.
90 // TODO(shess): Think up a crazy way to get out from having to support
91 // this forever.
92 TEST_F(SQLiteFeaturesTest, FTS2) {
93 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)"));
95 #endif
97 // fts3 is used for current history files, and also for WebDatabase.
98 TEST_F(SQLiteFeaturesTest, FTS3) {
99 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
102 } // namespace