OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "sql/test/test_helpers.h" | 5 #include "sql/test/test_helpers.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 CorruptSizeInHeaderMemory(header, db_size); | 92 CorruptSizeInHeaderMemory(header, db_size); |
93 | 93 |
94 if (0 != fseek(file.get(), 0, SEEK_SET)) | 94 if (0 != fseek(file.get(), 0, SEEK_SET)) |
95 return false; | 95 return false; |
96 if (1u != fwrite(header, sizeof(header), 1, file.get())) | 96 if (1u != fwrite(header, sizeof(header), 1, file.get())) |
97 return false; | 97 return false; |
98 | 98 |
99 return true; | 99 return true; |
100 } | 100 } |
101 | 101 |
| 102 bool CorruptSizeInHeaderWithLock(const base::FilePath& db_path) { |
| 103 sql::Connection db; |
| 104 if (!db.Open(db_path)) |
| 105 return false; |
| 106 |
| 107 // Prevent anyone else from using the database. The transaction is |
| 108 // rolled back when |db| is destroyed. |
| 109 if (!db.Execute("BEGIN EXCLUSIVE")) |
| 110 return false; |
| 111 |
| 112 return CorruptSizeInHeader(db_path); |
| 113 } |
| 114 |
102 void CorruptSizeInHeaderMemory(unsigned char* header, int64_t db_size) { | 115 void CorruptSizeInHeaderMemory(unsigned char* header, int64_t db_size) { |
103 const size_t kPageSizeOffset = 16; | 116 const size_t kPageSizeOffset = 16; |
104 const size_t kFileChangeCountOffset = 24; | 117 const size_t kFileChangeCountOffset = 24; |
105 const size_t kPageCountOffset = 28; | 118 const size_t kPageCountOffset = 28; |
106 const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset | 119 const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset |
107 | 120 |
108 const unsigned page_size = ReadBigEndian(header + kPageSizeOffset, 2); | 121 const unsigned page_size = ReadBigEndian(header + kPageSizeOffset, 2); |
109 | 122 |
110 // One larger than the expected size. | 123 // One larger than the expected size. |
111 const unsigned page_count = | 124 const unsigned page_count = |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check")); | 265 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check")); |
253 | 266 |
254 // SQLite should always return a row of data. | 267 // SQLite should always return a row of data. |
255 EXPECT_TRUE(statement.Step()); | 268 EXPECT_TRUE(statement.Step()); |
256 | 269 |
257 return statement.ColumnString(0); | 270 return statement.ColumnString(0); |
258 } | 271 } |
259 | 272 |
260 } // namespace test | 273 } // namespace test |
261 } // namespace sql | 274 } // namespace sql |
OLD | NEW |