OLD | NEW |
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/statement.h" | 8 #include "sql/statement.h" |
9 #include "sql/transaction.h" | 9 #include "sql/transaction.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/sqlite/sqlite3.h" | 11 #include "third_party/sqlite/sqlite3.h" |
12 | 12 |
13 class SQLTransactionTest : public testing::Test { | 13 class SQLTransactionTest : public testing::Test { |
14 public: | 14 public: |
15 virtual void SetUp() { | 15 void SetUp() override { |
16 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 16 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
17 ASSERT_TRUE(db_.Open( | 17 ASSERT_TRUE(db_.Open( |
18 temp_dir_.path().AppendASCII("SQLTransactionTest.db"))); | 18 temp_dir_.path().AppendASCII("SQLTransactionTest.db"))); |
19 | 19 |
20 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); | 20 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); |
21 } | 21 } |
22 | 22 |
23 virtual void TearDown() { | 23 void TearDown() override { db_.Close(); } |
24 db_.Close(); | |
25 } | |
26 | 24 |
27 sql::Connection& db() { return db_; } | 25 sql::Connection& db() { return db_; } |
28 | 26 |
29 // Returns the number of rows in table "foo". | 27 // Returns the number of rows in table "foo". |
30 int CountFoo() { | 28 int CountFoo() { |
31 sql::Statement count(db().GetUniqueStatement("SELECT count(*) FROM foo")); | 29 sql::Statement count(db().GetUniqueStatement("SELECT count(*) FROM foo")); |
32 count.Step(); | 30 count.Step(); |
33 return count.ColumnInt(0); | 31 return count.ColumnInt(0); |
34 } | 32 } |
35 | 33 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 EXPECT_EQ(1, db().transaction_nesting()); | 120 EXPECT_EQ(1, db().transaction_nesting()); |
123 { | 121 { |
124 sql::Transaction inner3(&db()); | 122 sql::Transaction inner3(&db()); |
125 EXPECT_FALSE(inner3.Begin()); | 123 EXPECT_FALSE(inner3.Begin()); |
126 EXPECT_EQ(1, db().transaction_nesting()); | 124 EXPECT_EQ(1, db().transaction_nesting()); |
127 } | 125 } |
128 } | 126 } |
129 EXPECT_EQ(0, db().transaction_nesting()); | 127 EXPECT_EQ(0, db().transaction_nesting()); |
130 EXPECT_EQ(0, CountFoo()); | 128 EXPECT_EQ(0, CountFoo()); |
131 } | 129 } |
OLD | NEW |