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 "sql/connection.h" | |
erikwright (departed)
2013/06/13 01:26:24
not required.
Scott Hess - ex-Googler
2013/06/13 03:23:27
Ah, lack of an abstract base class means it can go
| |
9 | |
10 namespace sql { | |
11 | |
12 // sql::Connection and sql::Statement treat most SQLite errors as | |
13 // fatal in debug mode. The intention is to catch inappropriate uses | |
14 // of SQL before the code is shipped to production. This makes it | |
15 // challenging to write tests for things like recovery from | |
16 // corruption. This scoper can be used to ignore selected errors | |
17 // during a test. Errors are ignored globally (on all connections). | |
18 // | |
19 // Since errors can be very context-dependent, the class is pedantic - | |
20 // specific errors must be ignored, and every error ignored must be | |
21 // seen. | |
22 // | |
23 // NOTE(shess): There are still fatal error cases this does not | |
24 // address. If your test is handling database errors and you're | |
25 // hitting a case not handled, contact me. | |
26 class SQL_EXPORT ScopedErrorIgnorer { | |
erikwright (departed)
2013/06/13 01:26:24
SQL_EXPORT is inappropriate. This target is a stat
Scott Hess - ex-Googler
2013/06/13 03:23:27
OK. I'm well into cargo-cult land, here.
| |
27 public: | |
28 ScopedErrorIgnorer(); | |
29 ~ScopedErrorIgnorer(); | |
30 | |
31 // Add an error to ignore. Extended error codes can be ignored | |
32 // specifically, or the base code can ignore an entire group | |
33 // (SQLITE_IOERR_* versus SQLITE_IOERR). | |
34 void IgnoreError(int err); | |
35 | |
36 // Allow containing test to check if the errors were encountered. | |
37 // Test is REQUIRED to call this before destruction. | |
38 // TODO(shess): How to handle ASSERT_X() cases which cause early | |
erikwright (departed)
2013/06/13 01:27:57
I guess this TODO is now closed?
Scott Hess - ex-Googler
2013/06/13 03:23:27
This relates to code like:
sql::ScopedErrorIgn
| |
39 // return in tests? | |
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_; | |
erikwright (departed)
2013/06/13 01:26:24
IWYU <set>
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
51 | |
52 // Errors which have been ignored. | |
53 std::set<int> errors_ignored_; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer); | |
erikwright (departed)
2013/06/13 01:26:24
IWYU base/basictypes.h
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
56 }; | |
57 | |
58 } // namespace sql | |
59 | |
60 #endif // SQL_TEST_SCOPED_ERROR_IGNORER_H_ | |
OLD | NEW |