| OLD | NEW |
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/files/scoped_file.h" | 7 #include "base/files/scoped_file.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
| 11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 12 #include "sql/connection.h" | 12 #include "sql/connection.h" |
| 13 #include "sql/correct_sql_test_base.h" | 13 #include "sql/correct_sql_test_base.h" |
| 14 #include "sql/meta_table.h" | 14 #include "sql/meta_table.h" |
| 15 #include "sql/proxy.h" |
| 15 #include "sql/statement.h" | 16 #include "sql/statement.h" |
| 16 #include "sql/test/error_callback_support.h" | 17 #include "sql/test/error_callback_support.h" |
| 17 #include "sql/test/scoped_error_ignorer.h" | 18 #include "sql/test/scoped_error_ignorer.h" |
| 18 #include "sql/test/test_helpers.h" | 19 #include "sql/test/test_helpers.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/sqlite/sqlite3.h" | 21 #include "third_party/sqlite/sqlite3.h" |
| 21 | 22 |
| 22 namespace sql { | 23 namespace sql { |
| 23 namespace test { | 24 namespace test { |
| 24 | 25 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 79 |
| 79 // Allow a test to add a SQLite function in a scoped context. | 80 // Allow a test to add a SQLite function in a scoped context. |
| 80 class ScopedScalarFunction { | 81 class ScopedScalarFunction { |
| 81 public: | 82 public: |
| 82 ScopedScalarFunction( | 83 ScopedScalarFunction( |
| 83 sql::Connection& db, | 84 sql::Connection& db, |
| 84 const char* function_name, | 85 const char* function_name, |
| 85 int args, | 86 int args, |
| 86 base::Callback<void(sqlite3_context*,int,sqlite3_value**)> cb) | 87 base::Callback<void(sqlite3_context*,int,sqlite3_value**)> cb) |
| 87 : db_(db.db_), function_name_(function_name), cb_(cb) { | 88 : db_(db.db_), function_name_(function_name), cb_(cb) { |
| 88 ::sqlite3_create_function_v2(db_, function_name, args, SQLITE_UTF8, | 89 sql::sqlite3_create_function_v2(db_, function_name, args, SQLITE_UTF8, |
| 89 this, &Run, NULL, NULL, NULL); | 90 this, &Run, NULL, NULL, NULL); |
| 90 } | 91 } |
| 91 ~ScopedScalarFunction() { | 92 ~ScopedScalarFunction() { |
| 92 ::sqlite3_create_function_v2(db_, function_name_, 0, SQLITE_UTF8, | 93 sql::sqlite3_create_function_v2(db_, function_name_, 0, SQLITE_UTF8, |
| 93 NULL, NULL, NULL, NULL, NULL); | 94 NULL, NULL, NULL, NULL, NULL); |
| 94 } | 95 } |
| 95 | 96 |
| 96 private: | 97 private: |
| 97 static void Run(sqlite3_context* context, int argc, sqlite3_value** argv) { | 98 static void Run(sqlite3_context* context, int argc, sqlite3_value** argv) { |
| 98 ScopedScalarFunction* t = static_cast<ScopedScalarFunction*>( | 99 ScopedScalarFunction* t = static_cast<ScopedScalarFunction*>( |
| 99 sqlite3_user_data(context)); | 100 sqlite3_user_data(context)); |
| 100 t->cb_.Run(context, argc, argv); | 101 t->cb_.Run(context, argc, argv); |
| 101 } | 102 } |
| 102 | 103 |
| 103 sqlite3* db_; | 104 sqlite3* db_; |
| 104 const char* function_name_; | 105 const char* function_name_; |
| 105 base::Callback<void(sqlite3_context*,int,sqlite3_value**)> cb_; | 106 base::Callback<void(sqlite3_context*,int,sqlite3_value**)> cb_; |
| 106 | 107 |
| 107 DISALLOW_COPY_AND_ASSIGN(ScopedScalarFunction); | 108 DISALLOW_COPY_AND_ASSIGN(ScopedScalarFunction); |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 // Allow a test to add a SQLite commit hook in a scoped context. | 111 // Allow a test to add a SQLite commit hook in a scoped context. |
| 111 class ScopedCommitHook { | 112 class ScopedCommitHook { |
| 112 public: | 113 public: |
| 113 ScopedCommitHook(sql::Connection& db, | 114 ScopedCommitHook(sql::Connection& db, |
| 114 base::Callback<int(void)> cb) | 115 base::Callback<int(void)> cb) |
| 115 : db_(db.db_), | 116 : db_(db.db_), |
| 116 cb_(cb) { | 117 cb_(cb) { |
| 117 ::sqlite3_commit_hook(db_, &Run, this); | 118 sql::sqlite3_commit_hook(db_, &Run, this); |
| 118 } | 119 } |
| 119 ~ScopedCommitHook() { | 120 ~ScopedCommitHook() { |
| 120 ::sqlite3_commit_hook(db_, NULL, NULL); | 121 sql::sqlite3_commit_hook(db_, NULL, NULL); |
| 121 } | 122 } |
| 122 | 123 |
| 123 private: | 124 private: |
| 124 static int Run(void* p) { | 125 static int Run(void* p) { |
| 125 ScopedCommitHook* t = static_cast<ScopedCommitHook*>(p); | 126 ScopedCommitHook* t = static_cast<ScopedCommitHook*>(p); |
| 126 return t->cb_.Run(); | 127 return t->cb_.Run(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 sqlite3* db_; | 130 sqlite3* db_; |
| 130 base::Callback<int(void)> cb_; | 131 base::Callback<int(void)> cb_; |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 samples = tester.GetHistogramSamplesSinceCreation(kCommitTime); | 1293 samples = tester.GetHistogramSamplesSinceCreation(kCommitTime); |
| 1293 ASSERT_TRUE(samples); | 1294 ASSERT_TRUE(samples); |
| 1294 // 100 for commit adjust, 1 for measuring COMMIT. | 1295 // 100 for commit adjust, 1 for measuring COMMIT. |
| 1295 EXPECT_EQ(101, samples->sum()); | 1296 EXPECT_EQ(101, samples->sum()); |
| 1296 | 1297 |
| 1297 samples = tester.GetHistogramSamplesSinceCreation(kAutoCommitTime); | 1298 samples = tester.GetHistogramSamplesSinceCreation(kAutoCommitTime); |
| 1298 EXPECT_EQ(0, samples->sum()); | 1299 EXPECT_EQ(0, samples->sum()); |
| 1299 } | 1300 } |
| 1300 | 1301 |
| 1301 } // namespace | 1302 } // namespace |
| OLD | NEW |