summaryrefslogtreecommitdiffstats
path: root/sql/test
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-12 01:38:56 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-12 01:38:56 +0000
commit98cf3002ce111ffce01bdc68f6a8b078abd2a77d (patch)
tree163daa4d84558802c0dad57b287cbea35a714a01 /sql/test
parent25ff086a748e9b399f8ca78cea3d2811a6545d9d (diff)
downloadchromium_src-98cf3002ce111ffce01bdc68f6a8b078abd2a77d.zip
chromium_src-98cf3002ce111ffce01bdc68f6a8b078abd2a77d.tar.gz
chromium_src-98cf3002ce111ffce01bdc68f6a8b078abd2a77d.tar.bz2
[sql] Callback and scoped-ignore tests for sql::Statement.
Test error callback and ScopedErrorIgnorer for running statements. Share error-callback test code between statement and connection tests. Test additional error-callback edge cases. Also fix callback use-after-free case. BUG=254584 Review URL: https://chromiumcodereview.appspot.com/17726002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/test')
-rw-r--r--sql/test/error_callback_support.cc28
-rw-r--r--sql/test/error_callback_support.h36
2 files changed, 64 insertions, 0 deletions
diff --git a/sql/test/error_callback_support.cc b/sql/test/error_callback_support.cc
new file mode 100644
index 0000000..9f0e22f3
--- /dev/null
+++ b/sql/test/error_callback_support.cc
@@ -0,0 +1,28 @@
+// Copyright 2013 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 "sql/test/error_callback_support.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace sql {
+
+void CaptureErrorCallback(int* error_pointer, int error, sql::Statement* stmt) {
+ *error_pointer = error;
+}
+
+ScopedErrorCallback::ScopedErrorCallback(
+ sql::Connection* db,
+ const sql::Connection::ErrorCallback& cb)
+ : db_(db) {
+ // Make sure someone isn't trying to nest things.
+ EXPECT_FALSE(db_->has_error_callback());
+ db_->set_error_callback(cb);
+}
+
+ScopedErrorCallback::~ScopedErrorCallback() {
+ db_->reset_error_callback();
+}
+
+} // namespace
diff --git a/sql/test/error_callback_support.h b/sql/test/error_callback_support.h
new file mode 100644
index 0000000..3026857
--- /dev/null
+++ b/sql/test/error_callback_support.h
@@ -0,0 +1,36 @@
+// Copyright 2013 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.
+
+#ifndef SQL_TEST_ERROR_CALLBACK_SUPPORT_H_
+#define SQL_TEST_ERROR_CALLBACK_SUPPORT_H_
+
+#include "sql/connection.h"
+
+namespace sql {
+
+// Helper to capture any errors into a local variable for testing.
+// For instance:
+// int error = SQLITE_OK;
+// ScopedErrorCallback sec(db, base::Bind(&CaptureErrorCallback, &error));
+// // Provoke SQLITE_CONSTRAINT on db.
+// EXPECT_EQ(SQLITE_CONSTRAINT, error);
+void CaptureErrorCallback(int* error_pointer, int error, sql::Statement* stmt);
+
+// Helper to set db's error callback and then reset it when it goes
+// out of scope.
+class ScopedErrorCallback {
+ public:
+ ScopedErrorCallback(sql::Connection* db,
+ const sql::Connection::ErrorCallback& cb);
+ ~ScopedErrorCallback();
+
+ private:
+ sql::Connection* db_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedErrorCallback);
+};
+
+} // namespace sql
+
+#endif // SQL_TEST_ERROR_CALLBACK_SUPPORT_H_