Chromium Code Reviews| 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 ASSERT_TRUE(Reopen()); | 704 ASSERT_TRUE(Reopen()); |
| 708 ASSERT_EQ(expected_schema, GetSchema(&db())); | 705 ASSERT_EQ(expected_schema, GetSchema(&db())); |
| 709 ASSERT_EQ(expected_data, ExecuteWithResults(&db(), kXSql, "|", "\n")); | 706 ASSERT_EQ(expected_data, ExecuteWithResults(&db(), kXSql, "|", "\n")); |
| 710 } | 707 } |
| 711 | 708 |
| 712 // Recover a golden file where an interior page has been manually modified so | 709 // Recover a golden file where an interior page has been manually modified so |
| 713 // that the number of cells is greater than will fit on a single page. This | 710 // that the number of cells is greater than will fit on a single page. This |
| 714 // case happened in <http://crbug.com/387868>. | 711 // case happened in <http://crbug.com/387868>. |
| 715 TEST_F(SQLRecoveryTest, Bug387868) { | 712 TEST_F(SQLRecoveryTest, Bug387868) { |
| 716 base::FilePath golden_path; | 713 base::FilePath golden_path; |
| 717 ASSERT_TRUE(PathService::Get(sql::test::DIR_TEST_DATA, &golden_path)); | 714 ASSERT_TRUE(PathService::Get(sql::test::DIR_TEST_DATA, &golden_path)); |
|
Scott Hess - ex-Googler
2016/03/02 01:00:32
This is failing on iOS. I'm guessing something ab
Scott Hess - ex-Googler
2016/03/07 21:50:13
OK, I think this needs to be disabled. DIR_SOURCE
Scott Hess - ex-Googler
2016/03/07 23:11:15
OK, figured it out by poking around with base_unit
| |
| 718 golden_path = golden_path.AppendASCII("recovery_387868"); | 715 golden_path = golden_path.AppendASCII("recovery_387868"); |
| 719 db().Close(); | 716 db().Close(); |
| 720 ASSERT_TRUE(base::CopyFile(golden_path, db_path())); | 717 ASSERT_TRUE(base::CopyFile(golden_path, db_path())); |
| 721 ASSERT_TRUE(Reopen()); | 718 ASSERT_TRUE(Reopen()); |
| 722 | 719 |
| 723 { | 720 { |
| 724 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); | 721 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); |
| 725 ASSERT_TRUE(recovery.get()); | 722 ASSERT_TRUE(recovery.get()); |
| 726 | 723 |
| 727 // Create the new version of the table. | 724 // Create the new version of the table. |
| 728 const char kCreateSql[] = | 725 const char kCreateSql[] = |
| 729 "CREATE TABLE x (id INTEGER PRIMARY KEY, t0 TEXT)"; | 726 "CREATE TABLE x (id INTEGER PRIMARY KEY, t0 TEXT)"; |
| 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 |