Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: sql/test/sql_test_base.h

Issue 1176653002: mandoline filesystem: add a sqlite3 vfs to proxy filesystem usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch cleanup now that gn check passes. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_TEST_SQL_TEST_BASE_H_
6 #define SQL_TEST_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 "sql/connection.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace sql {
15
16 class Connection;
17
18 // Base class for SQL tests.
19 //
20 // WARNING: We want to run the same gtest based unit test code both against
21 // chromium (which uses this implementation here), and the mojo code (which
22 // uses a different class named SQLTestBase). These two classes need to have
23 // the same interface because we compile time switch them based on a
24 // #define. We need to have two different implementations because the mojo
25 // version derives from something other than mojo::test::ApplicationTestBase
26 // instead of testing::Test.
27 class SQLTestBase : public testing::Test {
28 public:
29 SQLTestBase();
30 ~SQLTestBase() override;
31
32 // Returns the path to the database.
33 base::FilePath db_path();
34
35 // Returns a connection to the database at db_path().
36 sql::Connection& db();
37
38 // Closes the current connection to the database and reopens it.
39 bool Reopen();
40
41 // Proxying method around base::PathExists.
42 bool GetPathExists(const base::FilePath& path);
43
44 // SQLite stores the database size in the header, and if the actual
45 // OS-derived size is smaller, the database is considered corrupt.
46 // [This case is actually a common form of corruption in the wild.]
47 // This helper sets the in-header size to one page larger than the
48 // actual file size. The resulting file will return SQLITE_CORRUPT
49 // for most operations unless PRAGMA writable_schema is turned ON.
50 //
51 // Returns false if any error occurs accessing the file.
52 bool CorruptSizeInHeaderOfPath(const base::FilePath& path);
53
54 // Writes "Now is the winter of our discontent." to the start of the file.
55 void WriteJunkToDatabase(bool truncate);
56
57 // Sets the database file size to 0.
58 void TruncateDatabase();
59
60 // Overridden from testing::Test:
61 void SetUp() override;
62 void TearDown() override;
63
64 private:
65 base::ScopedTempDir temp_dir_;
66 sql::Connection db_;
67
68 DISALLOW_COPY_AND_ASSIGN(SQLTestBase);
69 };
70
71 } // namespace sql
72
73 #endif // SQL_TEST_SQL_TEST_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698