OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SQL_TEST_SCOPED_ERROR_IGNORER_H_ | 5 #ifndef SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
6 #define SQL_TEST_SCOPED_ERROR_IGNORER_H_ | 6 #define SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "sql/connection.h" | 11 #include "sql/connection.h" |
12 | 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. |
13 namespace sql { | 18 namespace sql { |
14 | 19 |
15 // sql::Connection and sql::Statement treat most SQLite errors as | 20 // sql::Connection and sql::Statement treat most SQLite errors as |
16 // fatal in debug mode. The intention is to catch inappropriate uses | 21 // fatal in debug mode. The intention is to catch inappropriate uses |
17 // of SQL before the code is shipped to production. This makes it | 22 // of SQL before the code is shipped to production. This makes it |
18 // challenging to write tests for things like recovery from | 23 // challenging to write tests for things like recovery from |
19 // corruption. This scoper can be used to ignore selected errors | 24 // corruption. This scoper can be used to ignore selected errors |
20 // during a test. Errors are ignored globally (on all connections). | 25 // during a test. Errors are ignored globally (on all connections). |
21 // | 26 // |
22 // Since errors can be very context-dependent, the class is pedantic - | 27 // Since errors can be very context-dependent, the class is pedantic - |
(...skipping 13 matching lines...) Expand all Loading... |
36 // (SQLITE_IOERR_* versus SQLITE_IOERR). | 41 // (SQLITE_IOERR_* versus SQLITE_IOERR). |
37 void IgnoreError(int err); | 42 void IgnoreError(int err); |
38 | 43 |
39 // Allow containing test to check if the errors were encountered. | 44 // Allow containing test to check if the errors were encountered. |
40 // Failure to call results in ADD_FAILURE() in destructor. | 45 // Failure to call results in ADD_FAILURE() in destructor. |
41 bool CheckIgnoredErrors(); | 46 bool CheckIgnoredErrors(); |
42 | 47 |
43 // Record an error and check if it should be ignored. | 48 // Record an error and check if it should be ignored. |
44 bool ShouldIgnore(int err); | 49 bool ShouldIgnore(int err); |
45 | 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 |
46 private: | 55 private: |
47 // Storage for callback passed to Connection::SetErrorIgnorer(). | 56 // Storage for callback passed to Connection::SetErrorIgnorer(). |
48 Connection::ErrorIgnorerCallback callback_; | 57 Connection::ErrorIgnorerCallback callback_; |
49 | 58 |
50 // Record whether CheckIgnoredErrors() has been called. | 59 // Record whether CheckIgnoredErrors() has been called. |
51 bool checked_; | 60 bool checked_; |
52 | 61 |
53 // Errors to ignore. | 62 // Errors to ignore. |
54 std::set<int> ignore_errors_; | 63 std::set<int> ignore_errors_; |
55 | 64 |
56 // Errors which have been ignored. | 65 // Errors which have been ignored. |
57 std::set<int> errors_ignored_; | 66 std::set<int> errors_ignored_; |
58 | 67 |
59 DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer); | 68 DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer); |
60 }; | 69 }; |
61 | 70 |
62 } // namespace sql | 71 } // namespace sql |
63 | 72 |
64 #endif // SQL_TEST_SCOPED_ERROR_IGNORER_H_ | 73 #endif // SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
OLD | NEW |