blob: 54e27c22ba513bcfb988ed9f7872bb440b9b234a [file] [log] [blame]
// Copyright 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_ERROR_CALLBACK_SUPPORT_H_
#define SQL_TEST_ERROR_CALLBACK_SUPPORT_H_
#include "base/memory/raw_ptr.h"
#include "sql/database.h"
namespace sql {
// Helper to capture any errors into a local variable for testing.
// For instance:
// int error = SQLITE_OK;
// ScopedErrorCallback sec(db, base::BindRepeating(&CaptureErrorCallback,
// &error));
// // Provoke SQLITE_CONSTRAINT on db.
// EXPECT_EQ(SQLITE_CONSTRAINT, error);
void CaptureErrorCallback(int* error_pointer, int error, sql::Statement* stmt);
// Helper to set db's error callback and then reset it when it goes
// out of scope.
class ScopedErrorCallback {
public:
ScopedErrorCallback(sql::Database* db,
const sql::Database::ErrorCallback& cb);
ScopedErrorCallback(const ScopedErrorCallback&) = delete;
ScopedErrorCallback& operator=(const ScopedErrorCallback&) = delete;
~ScopedErrorCallback();
private:
raw_ptr<sql::Database> db_;
};
} // namespace sql
#endif // SQL_TEST_ERROR_CALLBACK_SUPPORT_H_