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