Home | History | Annotate | Download | only in test
      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_ERROR_CALLBACK_SUPPORT_H_
      6 #define SQL_TEST_ERROR_CALLBACK_SUPPORT_H_
      7 
      8 #include "sql/connection.h"
      9 
     10 namespace sql {
     11 
     12 // Helper to capture any errors into a local variable for testing.
     13 // For instance:
     14 //   int error = SQLITE_OK;
     15 //   ScopedErrorCallback sec(db, base::Bind(&CaptureErrorCallback, &error));
     16 //   // Provoke SQLITE_CONSTRAINT on db.
     17 //   EXPECT_EQ(SQLITE_CONSTRAINT, error);
     18 void CaptureErrorCallback(int* error_pointer, int error, sql::Statement* stmt);
     19 
     20 // Helper to set db's error callback and then reset it when it goes
     21 // out of scope.
     22 class ScopedErrorCallback {
     23  public:
     24   ScopedErrorCallback(sql::Connection* db,
     25                       const sql::Connection::ErrorCallback& cb);
     26   ~ScopedErrorCallback();
     27 
     28  private:
     29   sql::Connection* db_;
     30 
     31   DISALLOW_COPY_AND_ASSIGN(ScopedErrorCallback);
     32 };
     33 
     34 }  // namespace sql
     35 
     36 #endif  // SQL_TEST_ERROR_CALLBACK_SUPPORT_H_
     37