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

Side by Side Diff: sql/sqlite_features_unittest.cc

Issue 1176653002: mandoline filesystem: add a sqlite3 vfs to proxy filesystem usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win 8 Created 5 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
« no previous file with comments | « sql/sql.gyp ('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/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "sql/connection.h" 10 #include "sql/connection.h"
11 #include "sql/statement.h" 11 #include "sql/statement.h"
12 #include "sql/test/sql_test_base.h"
12 #include "sql/test/test_helpers.h" 13 #include "sql/test/test_helpers.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/sqlite/sqlite3.h" 15 #include "third_party/sqlite/sqlite3.h"
15 16
16 // Test that certain features are/are-not enabled in our SQLite. 17 // Test that certain features are/are-not enabled in our SQLite.
17 18
18 namespace { 19 namespace {
19 20
20 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, 21 void CaptureErrorCallback(int* error_pointer, std::string* sql_text,
21 int error, sql::Statement* stmt) { 22 int error, sql::Statement* stmt) {
22 *error_pointer = error; 23 *error_pointer = error;
23 const char* text = stmt ? stmt->GetSQLStatement() : NULL; 24 const char* text = stmt ? stmt->GetSQLStatement() : NULL;
24 *sql_text = text ? text : "no statement available"; 25 *sql_text = text ? text : "no statement available";
25 } 26 }
26 27
27 class SQLiteFeaturesTest : public testing::Test { 28 class SQLiteFeaturesTest : public sql::SQLTestBase {
28 public: 29 public:
29 SQLiteFeaturesTest() : error_(SQLITE_OK) {} 30 SQLiteFeaturesTest() : error_(SQLITE_OK) {}
30 31
31 void SetUp() override { 32 void SetUp() override {
32 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 33 SQLTestBase::SetUp();
33 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
34 34
35 // The error delegate will set |error_| and |sql_text_| when any sqlite 35 // The error delegate will set |error_| and |sql_text_| when any sqlite
36 // statement operation returns an error code. 36 // statement operation returns an error code.
37 db_.set_error_callback(base::Bind(&CaptureErrorCallback, 37 db().set_error_callback(
38 &error_, &sql_text_)); 38 base::Bind(&CaptureErrorCallback, &error_, &sql_text_));
39 } 39 }
40 40
41 void TearDown() override { 41 void TearDown() override {
42 // If any error happened the original sql statement can be found in 42 // If any error happened the original sql statement can be found in
43 // |sql_text_|. 43 // |sql_text_|.
44 EXPECT_EQ(SQLITE_OK, error_) << sql_text_; 44 EXPECT_EQ(SQLITE_OK, error_) << sql_text_;
45 db_.Close(); 45
46 SQLTestBase::TearDown();
46 } 47 }
47 48
48 sql::Connection& db() { return db_; }
49 int error() { return error_; } 49 int error() { return error_; }
50 50
51 private: 51 private:
52 base::ScopedTempDir temp_dir_;
53 sql::Connection db_;
54
55 // The error code of the most recent error. 52 // The error code of the most recent error.
56 int error_; 53 int error_;
57 // Original statement which has caused the error. 54 // Original statement which has caused the error.
58 std::string sql_text_; 55 std::string sql_text_;
59 }; 56 };
60 57
61 // Do not include fts1 support, it is not useful, and nobody is 58 // Do not include fts1 support, it is not useful, and nobody is
62 // looking at it. 59 // looking at it.
63 TEST_F(SQLiteFeaturesTest, NoFTS1) { 60 TEST_F(SQLiteFeaturesTest, NoFTS1) {
64 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode( 61 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows)); 137 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows));
141 EXPECT_EQ(2u, rows); 138 EXPECT_EQ(2u, rows);
142 139
143 // Deleting the parent should cascade, i.e., delete the children as well. 140 // Deleting the parent should cascade, i.e., delete the children as well.
144 ASSERT_TRUE(db().Execute("DELETE FROM parents")); 141 ASSERT_TRUE(db().Execute("DELETE FROM parents"));
145 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows)); 142 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows));
146 EXPECT_EQ(0u, rows); 143 EXPECT_EQ(0u, rows);
147 } 144 }
148 145
149 } // namespace 146 } // namespace
OLDNEW
« no previous file with comments | « sql/sql.gyp ('k') | sql/statement_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698