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

Side by Side Diff: sql/transaction_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: Merge with ToT and fix the test import. 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
« sql/test/test_helpers.cc ('K') | « sql/test/test_helpers.cc ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "sql/connection.h" 7 #include "sql/connection.h"
8 #include "sql/correct_sql_test_base.h"
8 #include "sql/statement.h" 9 #include "sql/statement.h"
9 #include "sql/transaction.h" 10 #include "sql/transaction.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/sqlite/sqlite3.h" 12 #include "third_party/sqlite/sqlite3.h"
12 13
13 class SQLTransactionTest : public testing::Test { 14 class SQLTransactionTest : public sql::SQLTestBase {
14 public: 15 public:
15 void SetUp() override { 16 void SetUp() override {
16 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 17 SQLTestBase::SetUp();
17 ASSERT_TRUE(db_.Open(
18 temp_dir_.path().AppendASCII("SQLTransactionTest.db")));
19 18
20 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); 19 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
21 } 20 }
22 21
23 void TearDown() override { db_.Close(); }
24
25 sql::Connection& db() { return db_; }
26
27 // Returns the number of rows in table "foo". 22 // Returns the number of rows in table "foo".
28 int CountFoo() { 23 int CountFoo() {
29 sql::Statement count(db().GetUniqueStatement("SELECT count(*) FROM foo")); 24 sql::Statement count(db().GetUniqueStatement("SELECT count(*) FROM foo"));
30 count.Step(); 25 count.Step();
31 return count.ColumnInt(0); 26 return count.ColumnInt(0);
32 } 27 }
33
34 private:
35 base::ScopedTempDir temp_dir_;
36 sql::Connection db_;
37 }; 28 };
38 29
39 TEST_F(SQLTransactionTest, Commit) { 30 TEST_F(SQLTransactionTest, Commit) {
40 { 31 {
41 sql::Transaction t(&db()); 32 sql::Transaction t(&db());
42 EXPECT_FALSE(t.is_open()); 33 EXPECT_FALSE(t.is_open());
43 EXPECT_TRUE(t.Begin()); 34 EXPECT_TRUE(t.Begin());
44 EXPECT_TRUE(t.is_open()); 35 EXPECT_TRUE(t.is_open());
45 36
46 EXPECT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (1, 2)")); 37 EXPECT_TRUE(db().Execute("INSERT INTO foo (a, b) VALUES (1, 2)"));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EXPECT_EQ(1, db().transaction_nesting()); 111 EXPECT_EQ(1, db().transaction_nesting());
121 { 112 {
122 sql::Transaction inner3(&db()); 113 sql::Transaction inner3(&db());
123 EXPECT_FALSE(inner3.Begin()); 114 EXPECT_FALSE(inner3.Begin());
124 EXPECT_EQ(1, db().transaction_nesting()); 115 EXPECT_EQ(1, db().transaction_nesting());
125 } 116 }
126 } 117 }
127 EXPECT_EQ(0, db().transaction_nesting()); 118 EXPECT_EQ(0, db().transaction_nesting());
128 EXPECT_EQ(0, CountFoo()); 119 EXPECT_EQ(0, CountFoo());
129 } 120 }
OLDNEW
« sql/test/test_helpers.cc ('K') | « sql/test/test_helpers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698