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

Unified Diff: sql/test/scoped_error_ignorer.cc

Issue 16664005: [sql] Framework for allowing tests to handle errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor along lines of comment #4. 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
« sql/test/scoped_error_ignorer.h ('K') | « sql/test/scoped_error_ignorer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/test/scoped_error_ignorer.cc
diff --git a/sql/test/scoped_error_ignorer.cc b/sql/test/scoped_error_ignorer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bd00bdbc929b4a18aa5ff9a641da7e1d9bee9f1b
--- /dev/null
+++ b/sql/test/scoped_error_ignorer.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
erikwright (departed) 2013/06/13 01:26:24 2013
Scott Hess - ex-Googler 2013/06/13 03:23:27 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sql/test/scoped_error_ignorer.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
erikwright (departed) 2013/06/13 01:26:24 not required.
Scott Hess - ex-Googler 2013/06/13 03:23:27 Done.
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace sql {
+
+ScopedErrorIgnorer::ScopedErrorIgnorer()
+ : checked_(false) {
+ Connection::SetErrorIgnorer(
erikwright (departed) 2013/06/13 01:26:24 include connection.h in this .cc file
Scott Hess - ex-Googler 2013/06/13 03:23:27 Done.
+ base::Bind(&sql::ScopedErrorIgnorer::ShouldIgnore,
erikwright (departed) 2013/06/13 01:26:24 no sql namespace required here.
Scott Hess - ex-Googler 2013/06/13 03:23:27 Done.
+ base::Unretained(this)));
+}
+
+ScopedErrorIgnorer::~ScopedErrorIgnorer() {
+ if (!checked_)
+ ADD_FAILURE() << " Test must call CheckIgnoredErrors()";
erikwright (departed) 2013/06/13 01:26:24 This can also be EXPECT_FALSE(checked) << "...";
Scott Hess - ex-Googler 2013/06/13 03:23:27 Done.
+
+ Connection::ResetErrorIgnorer();
+}
+
+void ScopedErrorIgnorer::IgnoreError(int err) {
+ if (ignore_errors_.count(err))
+ ADD_FAILURE() << " Error " << err << " is already ignored";
erikwright (departed) 2013/06/13 01:26:24 same here.
Scott Hess - ex-Googler 2013/06/13 03:23:27 Done.
+ ignore_errors_.insert(err);
+}
+
+bool ScopedErrorIgnorer::CheckIgnoredErrors() {
+ checked_ = true;
+ return errors_ignored_ == ignore_errors_;
+}
+
+bool ScopedErrorIgnorer::ShouldIgnore(int err) {
+ // Look for extended code.
+ if (ignore_errors_.count(err) > 0) {
+ // Record that the error was seen and ignore it.
+ errors_ignored_.insert(err);
+ return true;
+ }
+
+ // Trim extended codes and check again.
+ int base_err = err & 0xff;
+ if (ignore_errors_.count(base_err) > 0) {
+ // Record that the error was seen and ignore it.
+ errors_ignored_.insert(base_err);
+ return true;
+ }
+
+ // Unexpected error.
+ ADD_FAILURE() << " Unexpected SQLite error " << err;
erikwright (departed) 2013/06/13 01:26:24 Personally I wonder why we would DCHECK on unexpec
Scott Hess - ex-Googler 2013/06/13 03:23:27 I am wondering that myself. I can see the utility
+
+ // TODO(shess): If it never makes sense to pass through an error
+ // under the test harness, then perhaps the ignore callback
+ // signature should be changed.
+ return true;
+}
+
+} // namespace sql
« sql/test/scoped_error_ignorer.h ('K') | « sql/test/scoped_error_ignorer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698