OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SQL_MOJO_SQL_TEST_BASE_H_ | |
6 #define SQL_MOJO_SQL_TEST_BASE_H_ | |
7 | |
8 #include "base/files/file_path.h" | |
9 #include "base/files/scoped_temp_dir.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "components/filesystem/public/interfaces/file_system.mojom.h" | |
12 #include "mojo/application/public/cpp/application_test_base.h" | |
13 #include "sql/connection.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace sql { | |
17 | |
18 class Connection; | |
19 class ScopedMojoFilesystemVFS; | |
20 | |
21 // Base class for SQL tests. | |
22 // | |
23 // WARNING: We want to run the same gtest based unit test code both against | |
24 // chromium (which uses this implementation here), and the mojo code (which | |
25 // uses a different class named SQLTestBase). These two classes need to have | |
26 // the same interface because we compile time switch them based on a | |
27 // #define. We need to have two different implementations because the mojo | |
28 // version derives from something other than mojo::test::ApplicationTestBase | |
29 // instead of testing::Test. | |
30 class SQLTestBase : public mojo::test::ApplicationTestBase { | |
31 public: | |
32 SQLTestBase(); | |
33 ~SQLTestBase() override; | |
34 | |
35 // Returns the path to the database. | |
36 base::FilePath db_path(); | |
37 | |
38 // Returns a connection to the database at db_path(). | |
39 sql::Connection& db(); | |
40 | |
41 // Closes the current connection to the database and reopens it. | |
42 bool Reopen(); | |
43 | |
44 // Proxying method around base::PathExists. | |
45 bool GetPathExists(const base::FilePath& path); | |
46 | |
47 // SQLite stores the database size in the header, and if the actual | |
48 // OS-derived size is smaller, the database is considered corrupt. | |
49 // [This case is actually a common form of corruption in the wild.] | |
50 // This helper sets the in-header size to one page larger than the | |
51 // actual file size. The resulting file will return SQLITE_CORRUPT | |
52 // for most operations unless PRAGMA writable_schema is turned ON. | |
53 // | |
54 // Returns false if any error occurs accessing the file. | |
55 bool CorruptSizeInHeaderOfPath(const base::FilePath& path); | |
56 | |
57 // Writes "Now is the winter of our discontent." to the start of the file. | |
Scott Hess - ex-Googler
2015/06/10 22:35:46
I don't think the string itself needs to be descri
Elliot Glaysher
2015/06/12 22:36:44
Done.
| |
58 void WriteJunkToDatabase(bool truncate); | |
59 | |
60 // Sets the database file size to 0. | |
61 void TruncateDatabase(); | |
62 | |
63 // Overridden from testing::Test: | |
64 void SetUp() override; | |
65 void TearDown() override; | |
66 | |
67 protected: | |
68 filesystem::FileSystemPtr& files() { return files_; } | |
69 | |
70 private: | |
71 filesystem::FileSystemPtr files_; | |
72 | |
73 scoped_ptr<ScopedMojoFilesystemVFS> vfs_; | |
74 sql::Connection db_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(SQLTestBase); | |
77 }; | |
78 | |
79 } // namespace sql | |
80 | |
81 #endif // SQL_MOJO_SQL_TEST_BASE_H_ | |
OLD | NEW |