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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: sql/connection_unittest.cc
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index 5aa7a9b588561e4c83c76a800360242d5de3a34b..ea0c8771362cc12d6afba170f95562a3f72dbaff 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -822,4 +822,45 @@ TEST_F(SQLConnectionTest, Attach) {
EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar"));
}
+TEST_F(SQLConnectionTest, Basic_QuickIntegrityCheck) {
michaeln 2013/12/13 22:47:05 Also, added some basic tests for the integrity che
+ const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
+ ASSERT_TRUE(db().Execute(kCreateSql));
+ EXPECT_TRUE(db().QuickIntegrityCheck());
+ db().Close();
+
+ ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path()));
+
+ {
+ sql::ScopedErrorIgnorer ignore_errors;
+ ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ db().Open(db_path());
+ EXPECT_FALSE(db().QuickIntegrityCheck());
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ }
+}
Scott Hess - ex-Googler 2013/12/13 23:15:46 Per offline discussion, given a table with an inde
+
+TEST_F(SQLConnectionTest, Basic_FullIntegrityCheck) {
+ const std::string kOk("ok");
+ std::vector<std::string> messages;
+
+ const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
+ ASSERT_TRUE(db().Execute(kCreateSql));
+ EXPECT_TRUE(db().FullIntegrityCheck(&messages));
+ EXPECT_EQ(1u, messages.size());
+ EXPECT_EQ(kOk, messages[0]);
+ db().Close();
+
+ ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path()));
+
+ {
+ sql::ScopedErrorIgnorer ignore_errors;
+ ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ db().Open(db_path());
+ EXPECT_TRUE(db().FullIntegrityCheck(&messages));
+ EXPECT_LT(1u, messages.size());
+ EXPECT_NE(kOk, messages[0]);
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ }
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698