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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 #if defined(SQLITE_ENABLE_FTS2) | 66 #if defined(SQLITE_ENABLE_FTS2) |
67 // fts2 is used for older history files, so we're signed on for keeping our | 67 // fts2 is used for older history files, so we're signed on for keeping our |
68 // version up-to-date. | 68 // version up-to-date. |
69 // TODO(shess): Think up a crazy way to get out from having to support | 69 // TODO(shess): Think up a crazy way to get out from having to support |
70 // this forever. | 70 // this forever. |
71 TEST_F(SQLiteFeaturesTest, FTS2) { | 71 TEST_F(SQLiteFeaturesTest, FTS2) { |
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 |
| 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)); |
| 83 |
| 84 ASSERT_TRUE(db().Execute("INSERT INTO foo (x) VALUES ('test')")); |
| 85 |
| 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)); |
| 90 } |
| 91 #endif |
74 #endif | 92 #endif |
75 | 93 |
76 // fts3 is used for current history files, and also for WebDatabase. | 94 // fts3 is used for current history files, and also for WebDatabase. |
77 TEST_F(SQLiteFeaturesTest, FTS3) { | 95 TEST_F(SQLiteFeaturesTest, FTS3) { |
78 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); | 96 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); |
79 } | 97 } |
80 | 98 |
| 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)); |
| 105 |
| 106 ASSERT_TRUE(db().Execute("INSERT INTO foo (x) VALUES ('test')")); |
| 107 |
| 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)); |
| 112 } |
| 113 #endif |
| 114 |
81 } // namespace | 115 } // namespace |
OLD | NEW |