blob: 101e038eb67ed24c5ea6d190b5c2df0515312760 [file] [log] [blame]
[email protected]60e60dd2012-04-28 08:16:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]67361b32011-04-12 20:13:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <string>
6
[email protected]526b4662013-06-14 04:09:127#include "base/bind.h"
thestig22dfc4012014-09-05 08:29:448#include "base/files/file_util.h"
[email protected]ea1a3f62012-11-16 20:34:239#include "base/files/scoped_temp_dir.h"
[email protected]f0a54b22011-07-19 18:40:2110#include "sql/connection.h"
11#include "sql/statement.h"
[email protected]67361b32011-04-12 20:13:0612#include "testing/gtest/include/gtest/gtest.h"
13#include "third_party/sqlite/sqlite3.h"
14
15// Test that certain features are/are-not enabled in our SQLite.
16
17namespace {
18
[email protected]526b4662013-06-14 04:09:1219void 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";
24}
[email protected]67361b32011-04-12 20:13:0625
26class SQLiteFeaturesTest : public testing::Test {
27 public:
[email protected]49dc4f22012-10-17 17:41:1628 SQLiteFeaturesTest() : error_(SQLITE_OK) {}
[email protected]67361b32011-04-12 20:13:0629
[email protected]3dbbf7d2013-02-06 18:13:5330 virtual void SetUp() {
[email protected]99034682012-06-13 03:31:1631 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
33
[email protected]49dc4f22012-10-17 17:41:1634 // The error delegate will set |error_| and |sql_text_| when any sqlite
35 // statement operation returns an error code.
[email protected]526b4662013-06-14 04:09:1236 db_.set_error_callback(base::Bind(&CaptureErrorCallback,
37 &error_, &sql_text_));
[email protected]67361b32011-04-12 20:13:0638 }
39
[email protected]3dbbf7d2013-02-06 18:13:5340 virtual void TearDown() {
[email protected]67361b32011-04-12 20:13:0641 // If any error happened the original sql statement can be found in
[email protected]49dc4f22012-10-17 17:41:1642 // |sql_text_|.
43 EXPECT_EQ(SQLITE_OK, error_);
[email protected]67361b32011-04-12 20:13:0644 db_.Close();
[email protected]67361b32011-04-12 20:13:0645 }
46
47 sql::Connection& db() { return db_; }
48
[email protected]67361b32011-04-12 20:13:0649 private:
[email protected]ea1a3f62012-11-16 20:34:2350 base::ScopedTempDir temp_dir_;
[email protected]67361b32011-04-12 20:13:0651 sql::Connection db_;
[email protected]49dc4f22012-10-17 17:41:1652
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_;
[email protected]67361b32011-04-12 20:13:0657};
58
59// Do not include fts1 support, it is not useful, and nobody is
60// looking at it.
61TEST_F(SQLiteFeaturesTest, NoFTS1) {
[email protected]eff1fa522011-12-12 23:50:5962 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode(
63 "CREATE VIRTUAL TABLE foo USING fts1(x)"));
[email protected]67361b32011-04-12 20:13:0664}
65
[email protected]e73e89222012-07-13 18:55:2266#if !defined(OS_IOS)
67// fts2 is used for older history files, so we're signed on for keeping our
68// version up-to-date. iOS does not include fts2, so this test does not run on
69// iOS.
[email protected]67361b32011-04-12 20:13:0670// TODO(shess): Think up a crazy way to get out from having to support
71// this forever.
72TEST_F(SQLiteFeaturesTest, FTS2) {
73 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)"));
74}
[email protected]e73e89222012-07-13 18:55:2275#endif
[email protected]67361b32011-04-12 20:13:0676
77// fts3 is used for current history files, and also for WebDatabase.
78TEST_F(SQLiteFeaturesTest, FTS3) {
79 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
80}
81
82} // namespace