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 #ifndef SQL_TEST_TEST_HELPERS_H_ | 5 #ifndef SQL_TEST_TEST_HELPERS_H_ |
6 #define SQL_TEST_TEST_HELPERS_H_ | 6 #define SQL_TEST_TEST_HELPERS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace sql { | 26 namespace sql { |
27 namespace test { | 27 namespace test { |
28 | 28 |
29 // SQLite stores the database size in the header, and if the actual | 29 // SQLite stores the database size in the header, and if the actual |
30 // OS-derived size is smaller, the database is considered corrupt. | 30 // OS-derived size is smaller, the database is considered corrupt. |
31 // [This case is actually a common form of corruption in the wild.] | 31 // [This case is actually a common form of corruption in the wild.] |
32 // This helper sets the in-header size to one page larger than the | 32 // This helper sets the in-header size to one page larger than the |
33 // actual file size. The resulting file will return SQLITE_CORRUPT | 33 // actual file size. The resulting file will return SQLITE_CORRUPT |
34 // for most operations unless PRAGMA writable_schema is turned ON. | 34 // for most operations unless PRAGMA writable_schema is turned ON. |
35 // | 35 // |
| 36 // This function operates on the raw database file, outstanding database |
| 37 // connections may not see the change because of the database cache. See |
| 38 // CorruptSizeInHeaderWithLock(). |
| 39 // |
36 // Returns false if any error occurs accessing the file. | 40 // Returns false if any error occurs accessing the file. |
37 bool CorruptSizeInHeader(const base::FilePath& db_path) WARN_UNUSED_RESULT; | 41 bool CorruptSizeInHeader(const base::FilePath& db_path) WARN_UNUSED_RESULT; |
38 | 42 |
39 // Common implementation of CorruptSizeInHeader() which operates on loaded | 43 // Common implementation of CorruptSizeInHeader() which operates on loaded |
40 // memory. Shared between CorruptSizeInHeader() and the the mojo proxy testing | 44 // memory. Shared between CorruptSizeInHeader() and the the mojo proxy testing |
41 // code. | 45 // code. |
42 void CorruptSizeInHeaderMemory(unsigned char* header, int64_t db_size); | 46 void CorruptSizeInHeaderMemory(unsigned char* header, int64_t db_size); |
43 | 47 |
| 48 // Call CorruptSizeInHeader() while holding a SQLite-compatible lock |
| 49 // on the database. This can be used to corrupt a database which is |
| 50 // already open elsewhere. Blocks until a write lock can be acquired. |
| 51 bool CorruptSizeInHeaderWithLock( |
| 52 const base::FilePath& db_path) WARN_UNUSED_RESULT; |
| 53 |
44 // Frequently corruption is a result of failure to atomically update | 54 // Frequently corruption is a result of failure to atomically update |
45 // pages in different structures. For instance, if an index update | 55 // pages in different structures. For instance, if an index update |
46 // takes effect but the corresponding table update does not. This | 56 // takes effect but the corresponding table update does not. This |
47 // helper restores the prior version of a b-tree root after running an | 57 // helper restores the prior version of a b-tree root after running an |
48 // update which changed that b-tree. The named b-tree must exist and | 58 // update which changed that b-tree. The named b-tree must exist and |
49 // must be a leaf node (either index or table). Returns true if the | 59 // must be a leaf node (either index or table). Returns true if the |
50 // on-disk file is successfully modified, and the restored page | 60 // on-disk file is successfully modified, and the restored page |
51 // differs from the updated page. | 61 // differs from the updated page. |
52 // | 62 // |
53 // The resulting database should be possible to open, and many | 63 // The resulting database should be possible to open, and many |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 95 |
86 // Return the results of running "PRAGMA integrity_check" on |db|. | 96 // Return the results of running "PRAGMA integrity_check" on |db|. |
87 // TODO(shess): sql::Connection::IntegrityCheck() is basically the | 97 // TODO(shess): sql::Connection::IntegrityCheck() is basically the |
88 // same, but not as convenient for testing. Maybe combine. | 98 // same, but not as convenient for testing. Maybe combine. |
89 std::string IntegrityCheck(sql::Connection* db) WARN_UNUSED_RESULT; | 99 std::string IntegrityCheck(sql::Connection* db) WARN_UNUSED_RESULT; |
90 | 100 |
91 } // namespace test | 101 } // namespace test |
92 } // namespace sql | 102 } // namespace sql |
93 | 103 |
94 #endif // SQL_TEST_TEST_HELPERS_H_ | 104 #endif // SQL_TEST_TEST_HELPERS_H_ |
OLD | NEW |