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

Side by Side 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: final gyp cleanup. 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 unified diff | Download patch | Annotate | Revision Log
« 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 (c) 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 ScopedErrorIgnorer::ScopedErrorIgnorer()
13 : checked_(false) {
14 callback_ =
15 base::Bind(&ScopedErrorIgnorer::ShouldIgnore, base::Unretained(this));
16 Connection::SetErrorIgnorer(&callback_);
17 }
18
19 ScopedErrorIgnorer::~ScopedErrorIgnorer() {
20 EXPECT_TRUE(checked_) << " Test must call CheckIgnoredErrors()";
21 Connection::ResetErrorIgnorer();
22 }
23
24 void ScopedErrorIgnorer::IgnoreError(int err) {
25 EXPECT_EQ(0u, ignore_errors_.count(err))
26 << " Error " << err << " is already ignored";
27 ignore_errors_.insert(err);
28 }
29
30 bool ScopedErrorIgnorer::CheckIgnoredErrors() {
31 checked_ = true;
32 return errors_ignored_ == ignore_errors_;
33 }
34
35 bool ScopedErrorIgnorer::ShouldIgnore(int err) {
36 // Look for extended code.
37 if (ignore_errors_.count(err) > 0) {
38 // Record that the error was seen and ignore it.
39 errors_ignored_.insert(err);
40 return true;
41 }
42
43 // Trim extended codes and check again.
44 int base_err = err & 0xff;
45 if (ignore_errors_.count(base_err) > 0) {
46 // Record that the error was seen and ignore it.
47 errors_ignored_.insert(base_err);
48 return true;
49 }
50
51 // Unexpected error.
52 ADD_FAILURE() << " Unexpected SQLite error " << err;
53
54 // TODO(shess): If it never makes sense to pass through an error
55 // under the test harness, then perhaps the ignore callback
56 // signature should be changed.
57 return true;
58 }
59
60 } // 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