summaryrefslogtreecommitdiffstats
path: root/app/sql
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-06-28 21:49:31 +0100
committerKristian Monsen <kristianm@google.com>2011-07-08 17:55:00 +0100
commitddb351dbec246cf1fab5ec20d2d5520909041de1 (patch)
tree158e3fb57bdcac07c7f1e767fde3c70687c9fbb1 /app/sql
parent6b92e04f5f151c896e3088e86f70db7081009308 (diff)
downloadexternal_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.zip
external_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.tar.gz
external_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.tar.bz2
Merge Chromium at r12.0.742.93: Initial merge by git
Change-Id: Ic5ee2fec31358bbee305f7e915442377bfa6cda6
Diffstat (limited to 'app/sql')
-rw-r--r--app/sql/connection.cc6
-rw-r--r--app/sql/connection.h4
-rw-r--r--app/sql/connection_unittest.cc17
-rw-r--r--app/sql/sqlite_features_unittest.cc100
-rw-r--r--app/sql/statement.h4
-rw-r--r--app/sql/statement_unittest.cc17
-rw-r--r--app/sql/transaction_unittest.cc18
7 files changed, 124 insertions, 42 deletions
diff --git a/app/sql/connection.cc b/app/sql/connection.cc
index 8c6a87a..111fde6 100644
--- a/app/sql/connection.cc
+++ b/app/sql/connection.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -137,13 +137,13 @@ void Connection::Preload() {
#if !defined(USE_SYSTEM_SQLITE)
// This function is only defined in Chromium's version of sqlite.
// Do not call it when using system sqlite.
- sqlite3Preload(db_);
+ sqlite3_preload(db_);
#endif
}
bool Connection::BeginTransaction() {
if (needs_rollback_) {
- DCHECK(transaction_nesting_ > 0);
+ DCHECK_GT(transaction_nesting_, 0);
// When we're going to rollback, fail on this begin and don't actually
// mark us as entering the nested transaction.
diff --git a/app/sql/connection.h b/app/sql/connection.h
index 0b685cc..d82b8b8 100644
--- a/app/sql/connection.h
+++ b/app/sql/connection.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,7 @@
#include <string>
#include "base/basictypes.h"
-#include "base/ref_counted.h"
+#include "base/memory/ref_counted.h"
#include "base/time.h"
class FilePath;
diff --git a/app/sql/connection_unittest.cc b/app/sql/connection_unittest.cc
index 0a14a9a..880bb81 100644
--- a/app/sql/connection_unittest.cc
+++ b/app/sql/connection_unittest.cc
@@ -1,12 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "app/sql/connection.h"
#include "app/sql/statement.h"
-#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/path_service.h"
+#include "base/memory/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
@@ -15,24 +14,18 @@ class SQLConnectionTest : public testing::Test {
SQLConnectionTest() {}
void SetUp() {
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_));
- path_ = path_.AppendASCII("SQLConnectionTest.db");
- file_util::Delete(path_, false);
- ASSERT_TRUE(db_.Open(path_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLConnectionTest.db")));
}
void TearDown() {
db_.Close();
-
- // If this fails something is going on with cleanup and later tests may
- // fail, so we want to identify problems right away.
- ASSERT_TRUE(file_util::Delete(path_, false));
}
sql::Connection& db() { return db_; }
private:
- FilePath path_;
+ ScopedTempDir temp_dir_;
sql::Connection db_;
};
diff --git a/app/sql/sqlite_features_unittest.cc b/app/sql/sqlite_features_unittest.cc
new file mode 100644
index 0000000..0ee63be
--- /dev/null
+++ b/app/sql/sqlite_features_unittest.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "app/sql/connection.h"
+#include "app/sql/statement.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/sqlite/sqlite3.h"
+
+// Test that certain features are/are-not enabled in our SQLite.
+
+namespace {
+
+
+class StatementErrorHandler : public sql::ErrorDelegate {
+ public:
+ StatementErrorHandler() : error_(SQLITE_OK) {}
+
+ virtual int OnError(int error, sql::Connection* connection,
+ sql::Statement* stmt) {
+ error_ = error;
+ const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL;
+ sql_text_ = sql_txt ? sql_txt : "no statement available";
+ return error;
+ }
+
+ int error() const { return error_; }
+
+ void reset_error() {
+ sql_text_.clear();
+ error_ = SQLITE_OK;
+ }
+
+ const char* sql_statement() const { return sql_text_.c_str(); }
+
+ private:
+ int error_;
+ std::string sql_text_;
+};
+
+class SQLiteFeaturesTest : public testing::Test {
+ public:
+ SQLiteFeaturesTest() : error_handler_(new StatementErrorHandler) {}
+
+ void SetUp() {
+ ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_));
+ path_ = path_.AppendASCII("SQLStatementTest.db");
+ file_util::Delete(path_, false);
+ ASSERT_TRUE(db_.Open(path_));
+ // The |error_handler_| will be called if any sqlite statement operation
+ // returns an error code.
+ db_.set_error_delegate(error_handler_);
+ }
+
+ void TearDown() {
+ // If any error happened the original sql statement can be found in
+ // error_handler_->sql_statement().
+ EXPECT_EQ(SQLITE_OK, error_handler_->error());
+ db_.Close();
+ // If this fails something is going on with cleanup and later tests may
+ // fail, so we want to identify problems right away.
+ ASSERT_TRUE(file_util::Delete(path_, false));
+ }
+
+ sql::Connection& db() { return db_; }
+
+ int sqlite_error() const { return error_handler_->error(); }
+ void reset_error() const { error_handler_->reset_error(); }
+
+ private:
+ FilePath path_;
+ sql::Connection db_;
+ scoped_refptr<StatementErrorHandler> error_handler_;
+};
+
+// Do not include fts1 support, it is not useful, and nobody is
+// looking at it.
+TEST_F(SQLiteFeaturesTest, NoFTS1) {
+ ASSERT_FALSE(db().Execute("CREATE VIRTUAL TABLE foo USING fts1(x)"));
+}
+
+// fts2 is used for older history files, so we're signed on for
+// keeping our version up-to-date.
+// TODO(shess): Think up a crazy way to get out from having to support
+// this forever.
+TEST_F(SQLiteFeaturesTest, FTS2) {
+ ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)"));
+}
+
+// fts3 is used for current history files, and also for WebDatabase.
+TEST_F(SQLiteFeaturesTest, FTS3) {
+ ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
+}
+
+} // namespace
diff --git a/app/sql/statement.h b/app/sql/statement.h
index eaaac41..6bf3949 100644
--- a/app/sql/statement.h
+++ b/app/sql/statement.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,7 @@
#include "app/sql/connection.h"
#include "base/basictypes.h"
-#include "base/ref_counted.h"
+#include "base/memory/ref_counted.h"
#include "base/string16.h"
namespace sql {
diff --git a/app/sql/statement_unittest.cc b/app/sql/statement_unittest.cc
index f9271a7..2cefd18 100644
--- a/app/sql/statement_unittest.cc
+++ b/app/sql/statement_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,9 +6,8 @@
#include "app/sql/connection.h"
#include "app/sql/statement.h"
-#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/path_service.h"
+#include "base/memory/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
@@ -43,10 +42,9 @@ class SQLStatementTest : public testing::Test {
SQLStatementTest() : error_handler_(new StatementErrorHandler) {}
void SetUp() {
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_));
- path_ = path_.AppendASCII("SQLStatementTest.db");
- file_util::Delete(path_, false);
- ASSERT_TRUE(db_.Open(path_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
+
// The |error_handler_| will be called if any sqlite statement operation
// returns an error code.
db_.set_error_delegate(error_handler_);
@@ -57,9 +55,6 @@ class SQLStatementTest : public testing::Test {
// error_handler_->sql_statement().
EXPECT_EQ(SQLITE_OK, error_handler_->error());
db_.Close();
- // If this fails something is going on with cleanup and later tests may
- // fail, so we want to identify problems right away.
- ASSERT_TRUE(file_util::Delete(path_, false));
}
sql::Connection& db() { return db_; }
@@ -68,7 +63,7 @@ class SQLStatementTest : public testing::Test {
void reset_error() const { error_handler_->reset_error(); }
private:
- FilePath path_;
+ ScopedTempDir temp_dir_;
sql::Connection db_;
scoped_refptr<StatementErrorHandler> error_handler_;
};
diff --git a/app/sql/transaction_unittest.cc b/app/sql/transaction_unittest.cc
index 9ca6bbd..c8e986d 100644
--- a/app/sql/transaction_unittest.cc
+++ b/app/sql/transaction_unittest.cc
@@ -1,13 +1,12 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "app/sql/connection.h"
#include "app/sql/statement.h"
#include "app/sql/transaction.h"
-#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/path_service.h"
+#include "base/memory/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
@@ -16,20 +15,15 @@ class SQLTransactionTest : public testing::Test {
SQLTransactionTest() {}
void SetUp() {
- ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_));
- path_ = path_.AppendASCII("SQLStatementTest.db");
- file_util::Delete(path_, false);
- ASSERT_TRUE(db_.Open(path_));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(db_.Open(
+ temp_dir_.path().AppendASCII("SQLTransactionTest.db")));
ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
}
void TearDown() {
db_.Close();
-
- // If this fails something is going on with cleanup and later tests may
- // fail, so we want to identify problems right away.
- ASSERT_TRUE(file_util::Delete(path_, false));
}
sql::Connection& db() { return db_; }
@@ -42,7 +36,7 @@ class SQLTransactionTest : public testing::Test {
}
private:
- FilePath path_;
+ ScopedTempDir temp_dir_;
sql::Connection db_;
};