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

Side by Side 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 unified diff | 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 »
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_expecter.h"
6
7 #include "base/bind.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace sql {
11 namespace test {
12
13 // static
14 int ScopedErrorExpecter::SQLiteLibVersionNumber() {
15 return sqlite3_libversion_number();
16 }
17
18 ScopedErrorExpecter::ScopedErrorExpecter()
19 : checked_(false) {
20 callback_ =
21 base::Bind(&ScopedErrorExpecter::ErrorSeen, base::Unretained(this));
22 Connection::SetErrorExpecter(&callback_);
23 }
24
25 ScopedErrorExpecter::~ScopedErrorExpecter() {
26 EXPECT_TRUE(checked_) << " Test must call SawExpectedErrors()";
27 Connection::ResetErrorExpecter();
28 }
29
30 void ScopedErrorExpecter::ExpectError(int err) {
31 EXPECT_EQ(0u, errors_expected_.count(err))
32 << " Error " << err << " is already expected";
33 errors_expected_.insert(err);
34 }
35
36 bool ScopedErrorExpecter::SawExpectedErrors() {
37 checked_ = true;
38 return errors_expected_ == errors_seen_;
39 }
40
41 bool ScopedErrorExpecter::ErrorSeen(int err) {
42 // Look for extended code.
43 if (errors_expected_.count(err) > 0) {
44 // Record that the error was seen.
45 errors_seen_.insert(err);
46 return true;
47 }
48
49 // Trim extended codes and check again.
50 int base_err = err & 0xff;
51 if (errors_expected_.count(base_err) > 0) {
52 // Record that the error was seen.
53 errors_seen_.insert(base_err);
54 return true;
55 }
56
57 // Unexpected error.
58 ADD_FAILURE() << " Unexpected SQLite error " << err;
59 return false;
60 }
61
62 } // namespace test
63 } // namespace sql
OLDNEW
« 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