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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "sql/connection.h" | 10 #include "sql/connection.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 bool CorruptSizeInHeader(const base::FilePath& db_path) { | 68 bool CorruptSizeInHeader(const base::FilePath& db_path) { |
69 // See http://www.sqlite.org/fileformat.html#database_header | 69 // See http://www.sqlite.org/fileformat.html#database_header |
70 const size_t kHeaderSize = 100; | 70 const size_t kHeaderSize = 100; |
71 const size_t kPageSizeOffset = 16; | 71 const size_t kPageSizeOffset = 16; |
72 const size_t kFileChangeCountOffset = 24; | 72 const size_t kFileChangeCountOffset = 24; |
73 const size_t kPageCountOffset = 28; | 73 const size_t kPageCountOffset = 28; |
74 const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset | 74 const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset |
75 | 75 |
76 unsigned char header[kHeaderSize]; | 76 unsigned char header[kHeaderSize]; |
77 | 77 |
78 file_util::ScopedFILE file(base::OpenFile(db_path, "rb+")); | 78 file_util::ScopedFILE file(file_util::OpenFile(db_path, "rb+")); |
79 if (!file.get()) | 79 if (!file.get()) |
80 return false; | 80 return false; |
81 | 81 |
82 if (0 != fseek(file.get(), 0, SEEK_SET)) | 82 if (0 != fseek(file.get(), 0, SEEK_SET)) |
83 return false; | 83 return false; |
84 if (1u != fread(header, sizeof(header), 1, file.get())) | 84 if (1u != fread(header, sizeof(header), 1, file.get())) |
85 return false; | 85 return false; |
86 | 86 |
87 int64 db_size = 0; | 87 int64 db_size = 0; |
88 if (!base::GetFileSize(db_path, &db_size)) | 88 if (!base::GetFileSize(db_path, &db_size)) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check")); | 241 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check")); |
242 | 242 |
243 // SQLite should always return a row of data. | 243 // SQLite should always return a row of data. |
244 EXPECT_TRUE(statement.Step()); | 244 EXPECT_TRUE(statement.Step()); |
245 | 245 |
246 return statement.ColumnString(0); | 246 return statement.ColumnString(0); |
247 } | 247 } |
248 | 248 |
249 } // namespace test | 249 } // namespace test |
250 } // namespace sql | 250 } // namespace sql |
OLD | NEW |