| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "sql/connection.h" | 10 #include "sql/connection.h" |
| 11 #include "sql/statement.h" | 11 #include "sql/statement.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/sqlite/sqlite3.h" | 13 #include "third_party/sqlite/sqlite3.h" |
| 14 | 14 |
| 15 // Test that certain features are/are-not enabled in our SQLite. | 15 // Test that certain features are/are-not enabled in our SQLite. |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, | 19 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, |
| 20 int error, sql::Statement* stmt) { | 20 int error, sql::Statement* stmt) { |
| 21 *error_pointer = error; | 21 *error_pointer = error; |
| 22 const char* text = stmt ? stmt->GetSQLStatement() : NULL; | 22 const char* text = stmt ? stmt->GetSQLStatement() : NULL; |
| 23 *sql_text = text ? text : "no statement available"; | 23 *sql_text = text ? text : "no statement available"; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class SQLiteFeaturesTest : public testing::Test { | 26 class SQLiteFeaturesTest : public testing::Test { |
| 27 public: | 27 public: |
| 28 SQLiteFeaturesTest() : error_(SQLITE_OK) {} | 28 SQLiteFeaturesTest() : error_(SQLITE_OK) {} |
| 29 | 29 |
| 30 virtual void SetUp() { | 30 void SetUp() override { |
| 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 32 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db"))); | 32 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db"))); |
| 33 | 33 |
| 34 // The error delegate will set |error_| and |sql_text_| when any sqlite | 34 // The error delegate will set |error_| and |sql_text_| when any sqlite |
| 35 // statement operation returns an error code. | 35 // statement operation returns an error code. |
| 36 db_.set_error_callback(base::Bind(&CaptureErrorCallback, | 36 db_.set_error_callback(base::Bind(&CaptureErrorCallback, |
| 37 &error_, &sql_text_)); | 37 &error_, &sql_text_)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual void TearDown() { | 40 void TearDown() override { |
| 41 // If any error happened the original sql statement can be found in | 41 // If any error happened the original sql statement can be found in |
| 42 // |sql_text_|. | 42 // |sql_text_|. |
| 43 EXPECT_EQ(SQLITE_OK, error_); | 43 EXPECT_EQ(SQLITE_OK, error_); |
| 44 db_.Close(); | 44 db_.Close(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 sql::Connection& db() { return db_; } | 47 sql::Connection& db() { return db_; } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 base::ScopedTempDir temp_dir_; | 50 base::ScopedTempDir temp_dir_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 72 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)")); | 72 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)")); |
| 73 } | 73 } |
| 74 #endif | 74 #endif |
| 75 | 75 |
| 76 // fts3 is used for current history files, and also for WebDatabase. | 76 // fts3 is used for current history files, and also for WebDatabase. |
| 77 TEST_F(SQLiteFeaturesTest, FTS3) { | 77 TEST_F(SQLiteFeaturesTest, FTS3) { |
| 78 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); | 78 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| OLD | NEW |