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

Side by Side Diff: sql/connection_unittest.cc

Issue 104593010: AppCache: Run a quick integrity check on the sqlite database when opening. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "sql/connection.h" 9 #include "sql/connection.h"
10 #include "sql/meta_table.h" 10 #include "sql/meta_table.h"
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); 815 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
816 } 816 }
817 817
818 // Detach succeeds outside of a transaction. 818 // Detach succeeds outside of a transaction.
819 db().RollbackTransaction(); 819 db().RollbackTransaction();
820 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint)); 820 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint));
821 821
822 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar")); 822 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar"));
823 } 823 }
824 824
825 TEST_F(SQLConnectionTest, Basic_QuickIntegrityCheck) {
michaeln 2013/12/13 22:47:05 Also, added some basic tests for the integrity che
826 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
827 ASSERT_TRUE(db().Execute(kCreateSql));
828 EXPECT_TRUE(db().QuickIntegrityCheck());
829 db().Close();
830
831 ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path()));
832
833 {
834 sql::ScopedErrorIgnorer ignore_errors;
835 ignore_errors.IgnoreError(SQLITE_CORRUPT);
836 db().Open(db_path());
837 EXPECT_FALSE(db().QuickIntegrityCheck());
838 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
839 }
840 }
Scott Hess - ex-Googler 2013/12/13 23:15:46 Per offline discussion, given a table with an inde
841
842 TEST_F(SQLConnectionTest, Basic_FullIntegrityCheck) {
843 const std::string kOk("ok");
844 std::vector<std::string> messages;
845
846 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
847 ASSERT_TRUE(db().Execute(kCreateSql));
848 EXPECT_TRUE(db().FullIntegrityCheck(&messages));
849 EXPECT_EQ(1u, messages.size());
850 EXPECT_EQ(kOk, messages[0]);
851 db().Close();
852
853 ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path()));
854
855 {
856 sql::ScopedErrorIgnorer ignore_errors;
857 ignore_errors.IgnoreError(SQLITE_CORRUPT);
858 db().Open(db_path());
859 EXPECT_TRUE(db().FullIntegrityCheck(&messages));
860 EXPECT_LT(1u, messages.size());
861 EXPECT_NE(kOk, messages[0]);
862 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
863 }
864 }
865
825 } // namespace 866 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698