Chromium Code Reviews| OLD | NEW |
|---|---|
| (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; | |
|
Mark P
2016/05/23 19:53:27
You changed this from false to true. I assume it
Scott Hess - ex-Googler
2016/06/03 00:02:12
Previously all cases returned true, which meant th
Mark P
2016/06/15 04:39:44
Acknowledged.
| |
| 60 } | |
| 61 | |
| 62 } // namespace test | |
| 63 } // namespace sql | |
| OLD | NEW |