| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 std::string sql_text_; | 58 std::string sql_text_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Do not include fts1 support, it is not useful, and nobody is | 61 // Do not include fts1 support, it is not useful, and nobody is |
| 62 // looking at it. | 62 // looking at it. |
| 63 TEST_F(SQLiteFeaturesTest, NoFTS1) { | 63 TEST_F(SQLiteFeaturesTest, NoFTS1) { |
| 64 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode( | 64 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode( |
| 65 "CREATE VIRTUAL TABLE foo USING fts1(x)")); | 65 "CREATE VIRTUAL TABLE foo USING fts1(x)")); |
| 66 } | 66 } |
| 67 | 67 |
| 68 #if defined(SQLITE_ENABLE_FTS2) | 68 // Do not include fts2 support, it is not useful, and nobody is |
| 69 // fts2 is used for older history files, so we're signed on for keeping our | 69 // looking at it. |
| 70 // version up-to-date. | 70 TEST_F(SQLiteFeaturesTest, NoFTS2) { |
| 71 // TODO(shess): Think up a crazy way to get out from having to support | 71 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode( |
| 72 // this forever. | 72 "CREATE VIRTUAL TABLE foo USING fts2(x)")); |
| 73 TEST_F(SQLiteFeaturesTest, FTS2) { | |
| 74 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)")); | |
| 75 } | 73 } |
| 76 | 74 |
| 77 // A standard SQLite will not include our patch. This includes iOS. | 75 // fts3 used to be used for history files, and may also be used by WebDatabase |
| 78 #if !defined(USE_SYSTEM_SQLITE) | 76 // clients. |
| 79 // Chromium fts2 was patched to treat "foo*" as a prefix search, though the icu | |
| 80 // tokenizer will return it as two tokens {"foo", "*"}. | |
| 81 TEST_F(SQLiteFeaturesTest, FTS2_Prefix) { | |
| 82 const char kCreateSql[] = | |
| 83 "CREATE VIRTUAL TABLE foo USING fts2(x, tokenize icu)"; | |
| 84 ASSERT_TRUE(db().Execute(kCreateSql)); | |
| 85 | |
| 86 ASSERT_TRUE(db().Execute("INSERT INTO foo (x) VALUES ('test')")); | |
| 87 | |
| 88 sql::Statement s(db().GetUniqueStatement( | |
| 89 "SELECT x FROM foo WHERE x MATCH 'te*'")); | |
| 90 ASSERT_TRUE(s.Step()); | |
| 91 EXPECT_EQ("test", s.ColumnString(0)); | |
| 92 } | |
| 93 #endif | |
| 94 #endif | |
| 95 | |
| 96 // fts3 is used for current history files, and also for WebDatabase. | |
| 97 TEST_F(SQLiteFeaturesTest, FTS3) { | 77 TEST_F(SQLiteFeaturesTest, FTS3) { |
| 98 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); | 78 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); |
| 99 } | 79 } |
| 100 | 80 |
| 101 #if !defined(USE_SYSTEM_SQLITE) | 81 #if !defined(USE_SYSTEM_SQLITE) |
| 102 // Test that fts3 doesn't need fts2's patch (see above). | 82 // Originally history used fts2, which Chromium patched to treat "foo*" as a |
| 83 // prefix search, though the icu tokenizer would return it as two tokens {"foo", |
| 84 // "*"}. Test that fts3 works correctly. |
| 103 TEST_F(SQLiteFeaturesTest, FTS3_Prefix) { | 85 TEST_F(SQLiteFeaturesTest, FTS3_Prefix) { |
| 104 const char kCreateSql[] = | 86 const char kCreateSql[] = |
| 105 "CREATE VIRTUAL TABLE foo USING fts3(x, tokenize icu)"; | 87 "CREATE VIRTUAL TABLE foo USING fts3(x, tokenize icu)"; |
| 106 ASSERT_TRUE(db().Execute(kCreateSql)); | 88 ASSERT_TRUE(db().Execute(kCreateSql)); |
| 107 | 89 |
| 108 ASSERT_TRUE(db().Execute("INSERT INTO foo (x) VALUES ('test')")); | 90 ASSERT_TRUE(db().Execute("INSERT INTO foo (x) VALUES ('test')")); |
| 109 | 91 |
| 110 sql::Statement s(db().GetUniqueStatement( | 92 sql::Statement s(db().GetUniqueStatement( |
| 111 "SELECT x FROM foo WHERE x MATCH 'te*'")); | 93 "SELECT x FROM foo WHERE x MATCH 'te*'")); |
| 112 ASSERT_TRUE(s.Step()); | 94 ASSERT_TRUE(s.Step()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows)); | 140 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows)); |
| 159 EXPECT_EQ(2u, rows); | 141 EXPECT_EQ(2u, rows); |
| 160 | 142 |
| 161 // Deleting the parent should cascade, i.e., delete the children as well. | 143 // Deleting the parent should cascade, i.e., delete the children as well. |
| 162 ASSERT_TRUE(db().Execute("DELETE FROM parents")); | 144 ASSERT_TRUE(db().Execute("DELETE FROM parents")); |
| 163 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows)); | 145 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows)); |
| 164 EXPECT_EQ(0u, rows); | 146 EXPECT_EQ(0u, rows); |
| 165 } | 147 } |
| 166 | 148 |
| 167 } // namespace | 149 } // namespace |
| OLD | NEW |