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

Side by Side Diff: sql/test/scoped_error_ignorer.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 unified diff | Download patch
« no previous file with comments | « sql/test/scoped_error_ignorer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sql/test/scoped_error_ignorer.h"
6
7 #include "base/bind.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace sql {
11
12 // static
13 int ScopedErrorIgnorer::SQLiteLibVersionNumber() {
14 return sqlite3_libversion_number();
15 }
16
17 ScopedErrorIgnorer::ScopedErrorIgnorer()
18 : checked_(false) {
19 callback_ =
20 base::Bind(&ScopedErrorIgnorer::ShouldIgnore, base::Unretained(this));
21 Connection::SetErrorIgnorer(&callback_);
22 }
23
24 ScopedErrorIgnorer::~ScopedErrorIgnorer() {
25 EXPECT_TRUE(checked_) << " Test must call CheckIgnoredErrors()";
26 Connection::ResetErrorIgnorer();
27 }
28
29 void ScopedErrorIgnorer::IgnoreError(int err) {
30 EXPECT_EQ(0u, ignore_errors_.count(err))
31 << " Error " << err << " is already ignored";
32 ignore_errors_.insert(err);
33 }
34
35 bool ScopedErrorIgnorer::CheckIgnoredErrors() {
36 checked_ = true;
37 return errors_ignored_ == ignore_errors_;
38 }
39
40 bool ScopedErrorIgnorer::ShouldIgnore(int err) {
41 // Look for extended code.
42 if (ignore_errors_.count(err) > 0) {
43 // Record that the error was seen and ignore it.
44 errors_ignored_.insert(err);
45 return true;
46 }
47
48 // Trim extended codes and check again.
49 int base_err = err & 0xff;
50 if (ignore_errors_.count(base_err) > 0) {
51 // Record that the error was seen and ignore it.
52 errors_ignored_.insert(base_err);
53 return true;
54 }
55
56 // Unexpected error.
57 ADD_FAILURE() << " Unexpected SQLite error " << err;
58
59 // TODO(shess): If it never makes sense to pass through an error
60 // under the test harness, then perhaps the ignore callback
61 // signature should be changed.
62 return true;
63 }
64
65 } // namespace sql
OLDNEW
« no previous file with comments | « sql/test/scoped_error_ignorer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698