This source file includes following definitions.
- IgnoreError
- CheckIgnoredErrors
- ShouldIgnore
#include "sql/test/scoped_error_ignorer.h"
#include "base/bind.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sql {
ScopedErrorIgnorer::ScopedErrorIgnorer()
: checked_(false) {
callback_ =
base::Bind(&ScopedErrorIgnorer::ShouldIgnore, base::Unretained(this));
Connection::SetErrorIgnorer(&callback_);
}
ScopedErrorIgnorer::~ScopedErrorIgnorer() {
EXPECT_TRUE(checked_) << " Test must call CheckIgnoredErrors()";
Connection::ResetErrorIgnorer();
}
void ScopedErrorIgnorer::IgnoreError(int err) {
EXPECT_EQ(0u, ignore_errors_.count(err))
<< " Error " << err << " is already ignored";
ignore_errors_.insert(err);
}
bool ScopedErrorIgnorer::CheckIgnoredErrors() {
checked_ = true;
return errors_ignored_ == ignore_errors_;
}
bool ScopedErrorIgnorer::ShouldIgnore(int err) {
if (ignore_errors_.count(err) > 0) {
errors_ignored_.insert(err);
return true;
}
int base_err = err & 0xff;
if (ignore_errors_.count(base_err) > 0) {
errors_ignored_.insert(base_err);
return true;
}
ADD_FAILURE() << " Unexpected SQLite error " << err;
return true;
}
}