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

Side by Side Diff: sql/sqlite_features_unittest.cc

Issue 16788002: Remove sql::ErrorDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase conflict Created 7 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 | Annotate | Revision Log
« no previous file with comments | « sql/connection.cc ('k') | sql/statement_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/bind.h"
7 #include "base/file_util.h" 8 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
9 #include "sql/connection.h" 10 #include "sql/connection.h"
10 #include "sql/statement.h" 11 #include "sql/statement.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/sqlite/sqlite3.h" 13 #include "third_party/sqlite/sqlite3.h"
13 14
14 // Test that certain features are/are-not enabled in our SQLite. 15 // Test that certain features are/are-not enabled in our SQLite.
15 16
16 namespace { 17 namespace {
17 18
18 class StatementErrorHandler : public sql::ErrorDelegate { 19 void CaptureErrorCallback(int* error_pointer, std::string* sql_text,
19 public: 20 int error, sql::Statement* stmt) {
20 StatementErrorHandler(int* error, std::string* sql_text) 21 *error_pointer = error;
21 : error_(error), 22 const char* text = stmt ? stmt->GetSQLStatement() : NULL;
22 sql_text_(sql_text) {} 23 *sql_text = text ? text : "no statement available";
23 24 }
24 virtual ~StatementErrorHandler() {}
25
26 virtual int OnError(int error, sql::Connection* connection,
27 sql::Statement* stmt) OVERRIDE {
28 *error_ = error;
29 const char* sql_txt = stmt ? stmt->GetSQLStatement() : NULL;
30 *sql_text_ = sql_txt ? sql_txt : "no statement available";
31 return error;
32 }
33
34 private:
35 int* error_;
36 std::string* sql_text_;
37
38 DISALLOW_COPY_AND_ASSIGN(StatementErrorHandler);
39 };
40 25
41 class SQLiteFeaturesTest : public testing::Test { 26 class SQLiteFeaturesTest : public testing::Test {
42 public: 27 public:
43 SQLiteFeaturesTest() : error_(SQLITE_OK) {} 28 SQLiteFeaturesTest() : error_(SQLITE_OK) {}
44 29
45 virtual void SetUp() { 30 virtual void SetUp() {
46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
47 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db"))); 32 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
48 33
49 // The error delegate will set |error_| and |sql_text_| when any sqlite 34 // The error delegate will set |error_| and |sql_text_| when any sqlite
50 // statement operation returns an error code. 35 // statement operation returns an error code.
51 db_.set_error_delegate(new StatementErrorHandler(&error_, &sql_text_)); 36 db_.set_error_callback(base::Bind(&CaptureErrorCallback,
37 &error_, &sql_text_));
52 } 38 }
53 39
54 virtual void TearDown() { 40 virtual void TearDown() {
55 // If any error happened the original sql statement can be found in 41 // If any error happened the original sql statement can be found in
56 // |sql_text_|. 42 // |sql_text_|.
57 EXPECT_EQ(SQLITE_OK, error_); 43 EXPECT_EQ(SQLITE_OK, error_);
58 db_.Close(); 44 db_.Close();
59 } 45 }
60 46
61 sql::Connection& db() { return db_; } 47 sql::Connection& db() { return db_; }
(...skipping 29 matching lines...) Expand all
91 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)")); 77 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)"));
92 } 78 }
93 #endif 79 #endif
94 80
95 // fts3 is used for current history files, and also for WebDatabase. 81 // fts3 is used for current history files, and also for WebDatabase.
96 TEST_F(SQLiteFeaturesTest, FTS3) { 82 TEST_F(SQLiteFeaturesTest, FTS3) {
97 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); 83 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
98 } 84 }
99 85
100 } // namespace 86 } // namespace
OLDNEW
« no previous file with comments | « sql/connection.cc ('k') | sql/statement_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698