Change ContentsView::SetActivePage to use States rather than indexes.
[chromium-blink-merge.git] / sql / test / scoped_error_ignorer.h
blob79559a1e38ce401817d0b2d1b83aa4ca37a9a587
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.
5 #ifndef SQL_TEST_SCOPED_ERROR_IGNORER_H_
6 #define SQL_TEST_SCOPED_ERROR_IGNORER_H_
8 #include <set>
10 #include "base/basictypes.h"
11 #include "sql/connection.h"
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"
17 // TODO(shess): sql::test:: seems like it could be in order for this.
18 namespace sql {
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).
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.
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();
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);
44 // Allow containing test to check if the errors were encountered.
45 // Failure to call results in ADD_FAILURE() in destructor.
46 bool CheckIgnoredErrors();
48 // Record an error and check if it should be ignored.
49 bool ShouldIgnore(int err);
51 // Expose sqlite3_libversion_number() so that clients don't have to add a
52 // dependency on third_party/sqlite.
53 static int SQLiteLibVersionNumber();
55 private:
56 // Storage for callback passed to Connection::SetErrorIgnorer().
57 Connection::ErrorIgnorerCallback callback_;
59 // Record whether CheckIgnoredErrors() has been called.
60 bool checked_;
62 // Errors to ignore.
63 std::set<int> ignore_errors_;
65 // Errors which have been ignored.
66 std::set<int> errors_ignored_;
68 DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer);
71 } // namespace sql
73 #endif // SQL_TEST_SCOPED_ERROR_IGNORER_H_