Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: sql/test/scoped_error_ignorer.h

Issue 1991503002: [sql] sql::ScopedErrorIgnorer rename to sql::test::ScopedErrorExpecter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sql/test/scoped_error_expecter.cc ('k') | sql/test/scoped_error_ignorer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « sql/test/scoped_error_expecter.cc ('k') | sql/test/scoped_error_ignorer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698