[Android] Temporarily suppress shift modifiers for detected tap gestures
[chromium-blink-merge.git] / sql / sqlite_features_unittest.cc
blob1aff80e9bbac20d11dfe40c9e90e0021166de30c
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/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.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 {
19 void CaptureErrorCallback(int* error_pointer, std::string* sql_text,
20 int error, sql::Statement* stmt) {
21 *error_pointer = error;
22 const char* text = stmt ? stmt->GetSQLStatement() : NULL;
23 *sql_text = text ? text : "no statement available";
26 class SQLiteFeaturesTest : public testing::Test {
27 public:
28 SQLiteFeaturesTest() : error_(SQLITE_OK) {}
30 void SetUp() override {
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
34 // The error delegate will set |error_| and |sql_text_| when any sqlite
35 // statement operation returns an error code.
36 db_.set_error_callback(base::Bind(&CaptureErrorCallback,
37 &error_, &sql_text_));
40 void TearDown() override {
41 // If any error happened the original sql statement can be found in
42 // |sql_text_|.
43 EXPECT_EQ(SQLITE_OK, error_);
44 db_.Close();
47 sql::Connection& db() { return db_; }
49 private:
50 base::ScopedTempDir temp_dir_;
51 sql::Connection db_;
53 // The error code of the most recent error.
54 int error_;
55 // Original statement which has caused the error.
56 std::string sql_text_;
59 // Do not include fts1 support, it is not useful, and nobody is
60 // looking at it.
61 TEST_F(SQLiteFeaturesTest, NoFTS1) {
62 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode(
63 "CREATE VIRTUAL TABLE foo USING fts1(x)"));
66 #if defined(SQLITE_ENABLE_FTS2)
67 // fts2 is used for older history files, so we're signed on for keeping our
68 // version up-to-date.
69 // TODO(shess): Think up a crazy way to get out from having to support
70 // this forever.
71 TEST_F(SQLiteFeaturesTest, FTS2) {
72 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)"));
75 // A standard SQLite will not include our patch. This includes iOS.
76 #if !defined(USE_SYSTEM_SQLITE)
77 // Chromium fts2 was patched to treat "foo*" as a prefix search, though the icu
78 // tokenizer will return it as two tokens {"foo", "*"}.
79 TEST_F(SQLiteFeaturesTest, FTS2_Prefix) {
80 const char kCreateSql[] =
81 "CREATE VIRTUAL TABLE foo USING fts2(x, tokenize icu)";
82 ASSERT_TRUE(db().Execute(kCreateSql));
84 ASSERT_TRUE(db().Execute("INSERT INTO foo (x) VALUES ('test')"));
86 sql::Statement s(db().GetUniqueStatement(
87 "SELECT x FROM foo WHERE x MATCH 'te*'"));
88 ASSERT_TRUE(s.Step());
89 EXPECT_EQ("test", s.ColumnString(0));
91 #endif
92 #endif
94 // fts3 is used for current history files, and also for WebDatabase.
95 TEST_F(SQLiteFeaturesTest, FTS3) {
96 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
99 #if !defined(USE_SYSTEM_SQLITE)
100 // Test that fts3 doesn't need fts2's patch (see above).
101 TEST_F(SQLiteFeaturesTest, FTS3_Prefix) {
102 const char kCreateSql[] =
103 "CREATE VIRTUAL TABLE foo USING fts3(x, tokenize icu)";
104 ASSERT_TRUE(db().Execute(kCreateSql));
106 ASSERT_TRUE(db().Execute("INSERT INTO foo (x) VALUES ('test')"));
108 sql::Statement s(db().GetUniqueStatement(
109 "SELECT x FROM foo WHERE x MATCH 'te*'"));
110 ASSERT_TRUE(s.Step());
111 EXPECT_EQ("test", s.ColumnString(0));
113 #endif
115 } // namespace