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 | |
178 // Test operation of the virtual table used by sql::Recovery. | 175 // Test operation of the virtual table used by sql::Recovery. |
179 TEST_F(SQLRecoveryTest, VirtualTable) { | 176 TEST_F(SQLRecoveryTest, VirtualTable) { |
180 const char kCreateSql[] = "CREATE TABLE x (t TEXT)"; | 177 const char kCreateSql[] = "CREATE TABLE x (t TEXT)"; |
181 ASSERT_TRUE(db().Execute(kCreateSql)); | 178 ASSERT_TRUE(db().Execute(kCreateSql)); |
182 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')")); | 179 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')")); |
183 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('That was a test')")); | 180 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('That was a test')")); |
184 | 181 |
185 // Successfully recover the database. | 182 // Successfully recover the database. |
186 { | 183 { |
187 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); | 184 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 ASSERT_TRUE(recovery->db()->Execute(kCreateSql)); | 727 ASSERT_TRUE(recovery->db()->Execute(kCreateSql)); |
731 | 728 |
732 size_t rows = 0; | 729 size_t rows = 0; |
733 EXPECT_TRUE(recovery->AutoRecoverTable("x", &rows)); | 730 EXPECT_TRUE(recovery->AutoRecoverTable("x", &rows)); |
734 EXPECT_EQ(43u, rows); | 731 EXPECT_EQ(43u, rows); |
735 | 732 |
736 // Successfully recovered. | 733 // Successfully recovered. |
737 EXPECT_TRUE(sql::Recovery::Recovered(std::move(recovery))); | 734 EXPECT_TRUE(sql::Recovery::Recovered(std::move(recovery))); |
738 } | 735 } |
739 } | 736 } |
740 #endif // !defined(USE_SYSTEM_SQLITE) | |
741 | 737 |
742 // Memory-mapped I/O interacts poorly with I/O errors. Make sure the recovery | 738 // Memory-mapped I/O interacts poorly with I/O errors. Make sure the recovery |
743 // database doesn't accidentally enable it. | 739 // database doesn't accidentally enable it. |
744 TEST_F(SQLRecoveryTest, NoMmap) { | 740 TEST_F(SQLRecoveryTest, NoMmap) { |
745 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); | 741 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); |
746 ASSERT_TRUE(recovery.get()); | 742 ASSERT_TRUE(recovery.get()); |
747 | 743 |
748 // In the current implementation, the PRAGMA successfully runs with no result | 744 // In the current implementation, the PRAGMA successfully runs with no result |
749 // rows. Running with a single result of |0| is also acceptable. | 745 // rows. Running with a single result of |0| is also acceptable. |
750 sql::Statement s(recovery->db()->GetUniqueStatement("PRAGMA mmap_size")); | 746 sql::Statement s(recovery->db()->GetUniqueStatement("PRAGMA mmap_size")); |
751 EXPECT_TRUE(!s.Step() || !s.ColumnInt64(0)); | 747 EXPECT_TRUE(!s.Step() || !s.ColumnInt64(0)); |
752 } | 748 } |
753 | 749 |
754 } // namespace | 750 } // namespace |
OLD | NEW |