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

Side by Side Diff: sql/recovery_unittest.cc

Issue 355093003: [sql] Test recovery of corrupt golden file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add sql.isolate Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « sql/BUILD.gn ('k') | sql/sql.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/path_service.h"
10 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
11 #include "sql/connection.h" 13 #include "sql/connection.h"
12 #include "sql/meta_table.h" 14 #include "sql/meta_table.h"
13 #include "sql/recovery.h" 15 #include "sql/recovery.h"
14 #include "sql/statement.h" 16 #include "sql/statement.h"
17 #include "sql/test/paths.h"
15 #include "sql/test/scoped_error_ignorer.h" 18 #include "sql/test/scoped_error_ignorer.h"
16 #include "sql/test/test_helpers.h" 19 #include "sql/test/test_helpers.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/sqlite/sqlite3.h" 21 #include "third_party/sqlite/sqlite3.h"
19 22
20 namespace { 23 namespace {
21 24
22 // Execute |sql|, and stringify the results with |column_sep| between 25 // Execute |sql|, and stringify the results with |column_sep| between
23 // columns and |row_sep| between rows. 26 // columns and |row_sep| between rows.
24 // TODO(shess): Promote this to a central testing helper. 27 // TODO(shess): Promote this to a central testing helper.
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 EXPECT_EQ(2u, rows); 679 EXPECT_EQ(2u, rows);
677 ASSERT_TRUE(sql::Recovery::Recovered(recovery.Pass())); 680 ASSERT_TRUE(sql::Recovery::Recovered(recovery.Pass()));
678 } 681 }
679 682
680 // Since the database was not corrupt, the entire schema and all 683 // Since the database was not corrupt, the entire schema and all
681 // data should be recovered. 684 // data should be recovered.
682 ASSERT_TRUE(Reopen()); 685 ASSERT_TRUE(Reopen());
683 ASSERT_EQ(orig_schema, GetSchema(&db())); 686 ASSERT_EQ(orig_schema, GetSchema(&db()));
684 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n")); 687 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
685 } 688 }
689
690 // Recover a golden file where an interior page has been manually modified so
691 // that the number of cells is greater than will fit on a single page. This
692 // case happened in <http://crbug.com/387868>.
693 TEST_F(SQLRecoveryTest, Bug387868) {
694 base::FilePath golden_path;
695 ASSERT_TRUE(PathService::Get(sql::test::DIR_TEST_DATA, &golden_path));
696 golden_path = golden_path.AppendASCII("recovery_387868");
697 db().Close();
698 ASSERT_TRUE(base::CopyFile(golden_path, db_path()));
699 ASSERT_TRUE(Reopen());
700
701 {
702 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
703 ASSERT_TRUE(recovery.get());
704
705 // Create the new version of the table.
706 const char kCreateSql[] =
707 "CREATE TABLE x (id INTEGER PRIMARY KEY, t0 TEXT)";
708 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
709
710 size_t rows = 0;
711 EXPECT_TRUE(recovery->AutoRecoverTable("x", 0, &rows));
712 EXPECT_EQ(43u, rows);
713
714 // Successfully recovered.
715 EXPECT_TRUE(sql::Recovery::Recovered(recovery.Pass()));
716 }
717 }
686 #endif // !defined(USE_SYSTEM_SQLITE) 718 #endif // !defined(USE_SYSTEM_SQLITE)
687 719
688 } // namespace 720 } // namespace
OLDNEW
« no previous file with comments | « sql/BUILD.gn ('k') | sql/sql.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698