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

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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sql/connection.cc ('k') | webkit/browser/appcache/appcache_database.h » ('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 (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) {
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 ASSERT_TRUE(db().Open(db_path()));
837 EXPECT_FALSE(db().QuickIntegrityCheck());
838 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
839 }
840 }
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 ASSERT_TRUE(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 // TODO(shess): CorruptTableOrIndex could be used to produce a
866 // file that would pass the quick check and fail the full check.
867 }
868
825 } // namespace 869 } // namespace
OLDNEW
« 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