Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: sql/connection_unittest.cc

Issue 17726002: [sql] Callback and scoped-ignore tests for sql::Statement. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sql/sql.gyp » ('j') | sql/statement_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection_unittest.cc
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index 1afd2dded3366baffe2dc6f831225a8b5395020f..5d894877e9c6b832b60a23508294958d420f6da7 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -2,16 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "sql/connection.h"
#include "sql/meta_table.h"
#include "sql/statement.h"
+#include "sql/test/error_callback_support.h"
#include "sql/test/scoped_error_ignorer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
+namespace {
+
class SQLConnectionTest : public testing::Test {
public:
SQLConnectionTest() {}
@@ -150,6 +154,21 @@ TEST_F(SQLConnectionTest, ScopedIgnoreError) {
ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
}
+TEST_F(SQLConnectionTest, ErrorCallback) {
+ const char* kCreateSql = "CREATE TABLE foo (id INTEGER UNIQUE)";
+ ASSERT_TRUE(db().Execute(kCreateSql));
+ ASSERT_TRUE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
+
+ int error = SQLITE_OK;
+ sql::ScopedErrorCallback sec(
+ &db(), base::Bind(&sql::CaptureErrorCallback, &error));
+
+ // Inserting something other than a number into the primary key
+ // should result in SQLITE_MISMATCH.
+ EXPECT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
+ EXPECT_EQ(SQLITE_CONSTRAINT, error);
+}
+
// Test that sql::Connection::Raze() results in a database without the
// tables from the original database.
TEST_F(SQLConnectionTest, Raze) {
@@ -426,3 +445,5 @@ TEST_F(SQLConnectionTest, Delete) {
EXPECT_FALSE(file_util::PathExists(db_path()));
EXPECT_FALSE(file_util::PathExists(journal));
}
+
+} // namespace
« no previous file with comments | « no previous file | sql/sql.gyp » ('j') | sql/statement_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698