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

Unified Diff: sql/test/scoped_error_expecter.cc

Issue 1991503002: [sql] sql::ScopedErrorIgnorer rename to sql::test::ScopedErrorExpecter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 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 | « sql/test/scoped_error_expecter.h ('k') | sql/test/scoped_error_ignorer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/test/scoped_error_expecter.cc
diff --git a/sql/test/scoped_error_expecter.cc b/sql/test/scoped_error_expecter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e19dc89cc97af37142759124d8b9b19be21100d6
--- /dev/null
+++ b/sql/test/scoped_error_expecter.cc
@@ -0,0 +1,63 @@
+// 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/scoped_error_expecter.h"
+
+#include "base/bind.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace sql {
+namespace test {
+
+// static
+int ScopedErrorExpecter::SQLiteLibVersionNumber() {
+ return sqlite3_libversion_number();
+}
+
+ScopedErrorExpecter::ScopedErrorExpecter()
+ : checked_(false) {
+ callback_ =
+ base::Bind(&ScopedErrorExpecter::ErrorSeen, base::Unretained(this));
+ Connection::SetErrorExpecter(&callback_);
+}
+
+ScopedErrorExpecter::~ScopedErrorExpecter() {
+ EXPECT_TRUE(checked_) << " Test must call SawExpectedErrors()";
+ Connection::ResetErrorExpecter();
+}
+
+void ScopedErrorExpecter::ExpectError(int err) {
+ EXPECT_EQ(0u, errors_expected_.count(err))
+ << " Error " << err << " is already expected";
+ errors_expected_.insert(err);
+}
+
+bool ScopedErrorExpecter::SawExpectedErrors() {
+ checked_ = true;
+ return errors_expected_ == errors_seen_;
+}
+
+bool ScopedErrorExpecter::ErrorSeen(int err) {
+ // Look for extended code.
+ if (errors_expected_.count(err) > 0) {
+ // Record that the error was seen.
+ errors_seen_.insert(err);
+ return true;
+ }
+
+ // Trim extended codes and check again.
+ int base_err = err & 0xff;
+ if (errors_expected_.count(base_err) > 0) {
+ // Record that the error was seen.
+ errors_seen_.insert(base_err);
+ return true;
+ }
+
+ // Unexpected error.
+ ADD_FAILURE() << " Unexpected SQLite error " << err;
+ return false;
+}
+
+} // namespace test
+} // namespace sql
« no previous file with comments | « sql/test/scoped_error_expecter.h ('k') | sql/test/scoped_error_ignorer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698