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

Unified Diff: sql/test/test_helpers.cc

Issue 1176653002: mandoline filesystem: add a sqlite3 vfs to proxy filesystem usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with ToT and fix the test import. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: sql/test/test_helpers.cc
diff --git a/sql/test/test_helpers.cc b/sql/test/test_helpers.cc
index 361b336452e6cf074583551b237d268d0d249a28..16f2a7e5a311227341d7e763c174e5608eb074fe 100644
--- a/sql/test/test_helpers.cc
+++ b/sql/test/test_helpers.cc
@@ -69,10 +69,6 @@ namespace test {
bool CorruptSizeInHeader(const base::FilePath& db_path) {
// See http://www.sqlite.org/fileformat.html#database_header
const size_t kHeaderSize = 100;
- const size_t kPageSizeOffset = 16;
- const size_t kFileChangeCountOffset = 24;
- const size_t kPageCountOffset = 28;
- const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset
unsigned char header[kHeaderSize];
@@ -89,6 +85,22 @@ bool CorruptSizeInHeader(const base::FilePath& db_path) {
if (!base::GetFileSize(db_path, &db_size))
return false;
+ CorruptSizeInHeaderMemory(header, db_size);
+
+ if (0 != fseek(file.get(), 0, SEEK_SET))
+ return false;
+ if (1u != fwrite(header, sizeof(header), 1, file.get()))
+ return false;
+
+ return true;
+}
+
+void CorruptSizeInHeaderMemory(unsigned char* header, int64_t db_size) {
Scott Hess - ex-Googler 2015/06/17 19:32:59 Makes sense to me!
+ const size_t kPageSizeOffset = 16;
+ const size_t kFileChangeCountOffset = 24;
+ const size_t kPageCountOffset = 28;
+ const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset
+
const unsigned page_size = ReadBigEndian(header + kPageSizeOffset, 2);
// One larger than the expected size.
@@ -101,13 +113,6 @@ bool CorruptSizeInHeader(const base::FilePath& db_path) {
unsigned change_count = ReadBigEndian(header + kFileChangeCountOffset, 4);
WriteBigEndian(change_count + 1, header + kFileChangeCountOffset, 4);
WriteBigEndian(change_count + 1, header + kVersionValidForOffset, 4);
-
- if (0 != fseek(file.get(), 0, SEEK_SET))
- return false;
- if (1u != fwrite(header, sizeof(header), 1, file.get()))
- return false;
-
- return true;
}
bool CorruptTableOrIndex(const base::FilePath& db_path,

Powered by Google App Engine
This is Rietveld 408576698