OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "sql/recovery.h" | 5 #include "sql/recovery.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 EXPECT_FALSE(db().is_open()); | 166 EXPECT_FALSE(db().is_open()); |
167 ASSERT_TRUE(Reopen()); | 167 ASSERT_TRUE(Reopen()); |
168 EXPECT_TRUE(db().is_open()); | 168 EXPECT_TRUE(db().is_open()); |
169 ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db())); | 169 ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db())); |
170 | 170 |
171 ASSERT_EQ("This is a test", | 171 ASSERT_EQ("This is a test", |
172 ExecuteWithResults(&db(), kXSql, "|", "\n")); | 172 ExecuteWithResults(&db(), kXSql, "|", "\n")); |
173 } | 173 } |
174 | 174 |
| 175 // The recovery virtual table is only supported for Chromium's SQLite. |
| 176 #if !defined(USE_SYSTEM_SQLITE) |
| 177 |
175 // Test operation of the virtual table used by sql::Recovery. | 178 // Test operation of the virtual table used by sql::Recovery. |
176 TEST_F(SQLRecoveryTest, VirtualTable) { | 179 TEST_F(SQLRecoveryTest, VirtualTable) { |
177 const char kCreateSql[] = "CREATE TABLE x (t TEXT)"; | 180 const char kCreateSql[] = "CREATE TABLE x (t TEXT)"; |
178 ASSERT_TRUE(db().Execute(kCreateSql)); | 181 ASSERT_TRUE(db().Execute(kCreateSql)); |
179 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')")); | 182 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')")); |
180 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('That was a test')")); | 183 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('That was a test')")); |
181 | 184 |
182 // Successfully recover the database. | 185 // Successfully recover the database. |
183 { | 186 { |
184 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); | 187 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 ASSERT_TRUE(recovery->db()->Execute(kCreateSql)); | 730 ASSERT_TRUE(recovery->db()->Execute(kCreateSql)); |
728 | 731 |
729 size_t rows = 0; | 732 size_t rows = 0; |
730 EXPECT_TRUE(recovery->AutoRecoverTable("x", &rows)); | 733 EXPECT_TRUE(recovery->AutoRecoverTable("x", &rows)); |
731 EXPECT_EQ(43u, rows); | 734 EXPECT_EQ(43u, rows); |
732 | 735 |
733 // Successfully recovered. | 736 // Successfully recovered. |
734 EXPECT_TRUE(sql::Recovery::Recovered(std::move(recovery))); | 737 EXPECT_TRUE(sql::Recovery::Recovered(std::move(recovery))); |
735 } | 738 } |
736 } | 739 } |
| 740 #endif // !defined(USE_SYSTEM_SQLITE) |
737 | 741 |
738 // Memory-mapped I/O interacts poorly with I/O errors. Make sure the recovery | 742 // Memory-mapped I/O interacts poorly with I/O errors. Make sure the recovery |
739 // database doesn't accidentally enable it. | 743 // database doesn't accidentally enable it. |
740 TEST_F(SQLRecoveryTest, NoMmap) { | 744 TEST_F(SQLRecoveryTest, NoMmap) { |
741 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); | 745 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); |
742 ASSERT_TRUE(recovery.get()); | 746 ASSERT_TRUE(recovery.get()); |
743 | 747 |
744 // In the current implementation, the PRAGMA successfully runs with no result | 748 // In the current implementation, the PRAGMA successfully runs with no result |
745 // rows. Running with a single result of |0| is also acceptable. | 749 // rows. Running with a single result of |0| is also acceptable. |
746 sql::Statement s(recovery->db()->GetUniqueStatement("PRAGMA mmap_size")); | 750 sql::Statement s(recovery->db()->GetUniqueStatement("PRAGMA mmap_size")); |
747 EXPECT_TRUE(!s.Step() || !s.ColumnInt64(0)); | 751 EXPECT_TRUE(!s.Step() || !s.ColumnInt64(0)); |
748 } | 752 } |
749 | 753 |
750 } // namespace | 754 } // namespace |
OLD | NEW |