Chromium Code Reviews| Index: sql/test/scoped_error_ignorer.h |
| diff --git a/sql/test/scoped_error_ignorer.h b/sql/test/scoped_error_ignorer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d685804ac6b43b32053057d5004d6de3c4e2b278 |
| --- /dev/null |
| +++ b/sql/test/scoped_error_ignorer.h |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
| +#define SQL_TEST_SCOPED_ERROR_IGNORER_H_ |
| + |
| +#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
|
| + |
| +namespace sql { |
| + |
| +// sql::Connection and sql::Statement treat most SQLite errors as |
| +// fatal in debug mode. The intention is to catch inappropriate uses |
| +// of SQL before the code is shipped to production. This makes it |
| +// challenging to write tests for things like recovery from |
| +// corruption. This scoper can be used to ignore selected errors |
| +// during a test. Errors are ignored globally (on all connections). |
| +// |
| +// Since errors can be very context-dependent, the class is pedantic - |
| +// specific errors must be ignored, and every error ignored must be |
| +// seen. |
| +// |
| +// NOTE(shess): There are still fatal error cases this does not |
| +// address. If your test is handling database errors and you're |
| +// hitting a case not handled, contact me. |
| +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.
|
| + public: |
| + ScopedErrorIgnorer(); |
| + ~ScopedErrorIgnorer(); |
| + |
| + // Add an error to ignore. Extended error codes can be ignored |
| + // specifically, or the base code can ignore an entire group |
| + // (SQLITE_IOERR_* versus SQLITE_IOERR). |
| + void IgnoreError(int err); |
| + |
| + // Allow containing test to check if the errors were encountered. |
| + // Test is REQUIRED to call this before destruction. |
| + // 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
|
| + // return in tests? |
| + bool CheckIgnoredErrors(); |
| + |
| + // Record an error and check if it should be ignored. |
| + bool ShouldIgnore(int err); |
| + |
| + private: |
| + // Record whether CheckIgnoredErrors() has been called. |
| + bool checked_; |
| + |
| + // Errors to ignore. |
| + 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.
|
| + |
| + // Errors which have been ignored. |
| + std::set<int> errors_ignored_; |
| + |
| + 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.
|
| +}; |
| + |
| +} // namespace sql |
| + |
| +#endif // SQL_TEST_SCOPED_ERROR_IGNORER_H_ |