chromeos: bluetooth: add BluetoothInputClient
[chromium-blink-merge.git] / sql / sqlite_features_unittest.cc
blobe5cca499727658f61e439f22b9769f66c5f5ac01
1 // Copyright (c) 2011 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_path.h"
8 #include "base/file_util.h"
9 #include "base/path_service.h"
10 #include "sql/connection.h"
11 #include "sql/statement.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/sqlite/sqlite3.h"
15 // Test that certain features are/are-not enabled in our SQLite.
17 namespace {
20 class StatementErrorHandler : public sql::ErrorDelegate {
21 public:
22 StatementErrorHandler() : error_(SQLITE_OK) {}
24 virtual int OnError(int error, sql::Connection* connection,
25 sql::Statement* stmt) {
26 error_ = error;
27 const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL;
28 sql_text_ = sql_txt ? sql_txt : "no statement available";
29 return error;
32 int error() const { return error_; }
34 void reset_error() {
35 sql_text_.clear();
36 error_ = SQLITE_OK;
39 const char* sql_statement() const { return sql_text_.c_str(); }
41 private:
42 int error_;
43 std::string sql_text_;
46 class SQLiteFeaturesTest : public testing::Test {
47 public:
48 SQLiteFeaturesTest() : error_handler_(new StatementErrorHandler) {}
50 void SetUp() {
51 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_));
52 path_ = path_.AppendASCII("SQLStatementTest.db");
53 file_util::Delete(path_, false);
54 ASSERT_TRUE(db_.Open(path_));
55 // The |error_handler_| will be called if any sqlite statement operation
56 // returns an error code.
57 db_.set_error_delegate(error_handler_);
60 void TearDown() {
61 // If any error happened the original sql statement can be found in
62 // error_handler_->sql_statement().
63 EXPECT_EQ(SQLITE_OK, error_handler_->error());
64 db_.Close();
65 // If this fails something is going on with cleanup and later tests may
66 // fail, so we want to identify problems right away.
67 ASSERT_TRUE(file_util::Delete(path_, false));
70 sql::Connection& db() { return db_; }
72 int sqlite_error() const { return error_handler_->error(); }
73 void reset_error() const { error_handler_->reset_error(); }
75 private:
76 FilePath path_;
77 sql::Connection db_;
78 scoped_refptr<StatementErrorHandler> error_handler_;
81 // Do not include fts1 support, it is not useful, and nobody is
82 // looking at it.
83 TEST_F(SQLiteFeaturesTest, NoFTS1) {
84 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode(
85 "CREATE VIRTUAL TABLE foo USING fts1(x)"));
88 // fts2 is used for older history files, so we're signed on for
89 // keeping our version up-to-date.
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)"));
96 // fts3 is used for current history files, and also for WebDatabase.
97 TEST_F(SQLiteFeaturesTest, FTS3) {
98 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
101 } // namespace