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

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: fixed clang error 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
« no previous file with comments | « sql/connection.cc ('k') | webkit/browser/appcache/appcache_database.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection_unittest.cc
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index 5aa7a9b588561e4c83c76a800360242d5de3a34b..304ddcddbccd3305e38a1def5b0d8e89747540c6 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -822,4 +822,48 @@ TEST_F(SQLConnectionTest, Attach) {
EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar"));
}
+TEST_F(SQLConnectionTest, Basic_QuickIntegrityCheck) {
+ 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);
+ ASSERT_TRUE(db().Open(db_path()));
+ EXPECT_FALSE(db().QuickIntegrityCheck());
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ }
+}
+
+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);
+ ASSERT_TRUE(db().Open(db_path()));
+ EXPECT_TRUE(db().FullIntegrityCheck(&messages));
+ EXPECT_LT(1u, messages.size());
+ EXPECT_NE(kOk, messages[0]);
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ }
+
+ // TODO(shess): CorruptTableOrIndex could be used to produce a
+ // file that would pass the quick check and fail the full check.
+}
+
} // namespace
« no previous file with comments | « sql/connection.cc ('k') | webkit/browser/appcache/appcache_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698