OLD | NEW |
(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 #ifndef SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
| 6 #define SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 |
| 12 namespace sql { |
| 13 |
| 14 // sql::Connection and sql::Statement treat most SQLite errors as |
| 15 // fatal in debug mode. The intention is to catch inappropriate uses |
| 16 // of SQL before the code is shipped to production. This makes it |
| 17 // challenging to write tests for things like recovery from |
| 18 // corruption. This scoper can be used to ignore selected errors |
| 19 // during a test. Errors are ignored globally (on all connections). |
| 20 // |
| 21 // Since errors can be very context-dependent, the class is pedantic - |
| 22 // specific errors must be ignored, and every error ignored must be |
| 23 // seen. |
| 24 // |
| 25 // NOTE(shess): There are still fatal error cases this does not |
| 26 // address. If your test is handling database errors and you're |
| 27 // hitting a case not handled, contact me. |
| 28 class ScopedErrorIgnorer { |
| 29 public: |
| 30 ScopedErrorIgnorer(); |
| 31 ~ScopedErrorIgnorer(); |
| 32 |
| 33 // Add an error to ignore. Extended error codes can be ignored |
| 34 // specifically, or the base code can ignore an entire group |
| 35 // (SQLITE_IOERR_* versus SQLITE_IOERR). |
| 36 void IgnoreError(int err); |
| 37 |
| 38 // Allow containing test to check if the errors were encountered. |
| 39 // Failure to call results in ADD_FAILURE() in destructor. |
| 40 bool CheckIgnoredErrors(); |
| 41 |
| 42 // Record an error and check if it should be ignored. |
| 43 bool ShouldIgnore(int err); |
| 44 |
| 45 private: |
| 46 // Record whether CheckIgnoredErrors() has been called. |
| 47 bool checked_; |
| 48 |
| 49 // Errors to ignore. |
| 50 std::set<int> ignore_errors_; |
| 51 |
| 52 // Errors which have been ignored. |
| 53 std::set<int> errors_ignored_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer); |
| 56 }; |
| 57 |
| 58 } // namespace sql |
| 59 |
| 60 #endif // SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
OLD | NEW |