| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_file.h" | 14 #include "base/files/scoped_file.h" |
| 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "sql/connection.h" | 16 #include "sql/connection.h" |
| 16 #include "sql/statement.h" | 17 #include "sql/statement.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 size_t CountSQLItemsOfType(sql::Connection* db, const char* type) { | 22 size_t CountSQLItemsOfType(sql::Connection* db, const char* type) { |
| 22 const char kTypeSQL[] = "SELECT COUNT(*) FROM sqlite_master WHERE type = ?"; | 23 const char kTypeSQL[] = "SELECT COUNT(*) FROM sqlite_master WHERE type = ?"; |
| 23 sql::Statement s(db->GetUniqueStatement(kTypeSQL)); | 24 sql::Statement s(db->GetUniqueStatement(kTypeSQL)); |
| 24 s.BindCString(0, type); | 25 s.BindCString(0, type); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 94 |
| 94 if (0 != fseek(file.get(), 0, SEEK_SET)) | 95 if (0 != fseek(file.get(), 0, SEEK_SET)) |
| 95 return false; | 96 return false; |
| 96 if (1u != fwrite(header, sizeof(header), 1, file.get())) | 97 if (1u != fwrite(header, sizeof(header), 1, file.get())) |
| 97 return false; | 98 return false; |
| 98 | 99 |
| 99 return true; | 100 return true; |
| 100 } | 101 } |
| 101 | 102 |
| 102 bool CorruptSizeInHeaderWithLock(const base::FilePath& db_path) { | 103 bool CorruptSizeInHeaderWithLock(const base::FilePath& db_path) { |
| 104 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 103 sql::Connection db; | 105 sql::Connection db; |
| 104 if (!db.Open(db_path)) | 106 if (!db.Open(db_path)) |
| 105 return false; | 107 return false; |
| 106 | 108 |
| 107 // Prevent anyone else from using the database. The transaction is | 109 // Prevent anyone else from using the database. The transaction is |
| 108 // rolled back when |db| is destroyed. | 110 // rolled back when |db| is destroyed. |
| 109 if (!db.Execute("BEGIN EXCLUSIVE")) | 111 if (!db.Execute("BEGIN EXCLUSIVE")) |
| 110 return false; | 112 return false; |
| 111 | 113 |
| 112 return CorruptSizeInHeader(db_path); | 114 return CorruptSizeInHeader(db_path); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (i > 0) | 290 if (i > 0) |
| 289 ret += column_sep; | 291 ret += column_sep; |
| 290 ret += s.ColumnString(i); | 292 ret += s.ColumnString(i); |
| 291 } | 293 } |
| 292 } | 294 } |
| 293 return ret; | 295 return ret; |
| 294 } | 296 } |
| 295 | 297 |
| 296 } // namespace test | 298 } // namespace test |
| 297 } // namespace sql | 299 } // namespace sql |
| OLD | NEW |