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

Unified Diff: sql/mojo/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 side-by-side diff with in-line comments
Download patch
Index: sql/mojo/sql_test_base.h
diff --git a/sql/mojo/sql_test_base.h b/sql/mojo/sql_test_base.h
new file mode 100644
index 0000000000000000000000000000000000000000..509ca63f07108ad517acd66e8ad09e817f9b12af
--- /dev/null
+++ b/sql/mojo/sql_test_base.h
@@ -0,0 +1,81 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SQL_MOJO_SQL_TEST_BASE_H_
+#define SQL_MOJO_SQL_TEST_BASE_H_
+
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/memory/scoped_ptr.h"
+#include "components/filesystem/public/interfaces/file_system.mojom.h"
+#include "mojo/application/public/cpp/application_test_base.h"
+#include "sql/connection.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace sql {
+
+class Connection;
+class ScopedMojoFilesystemVFS;
+
+// Base class for SQL tests.
+//
+// WARNING: We want to run the same gtest based unit test code both against
+// chromium (which uses this implementation here), and the mojo code (which
+// uses a different class named SQLTestBase). These two classes need to have
+// the same interface because we compile time switch them based on a
+// #define. We need to have two different implementations because the mojo
+// version derives from something other than mojo::test::ApplicationTestBase
+// instead of testing::Test.
+class SQLTestBase : public mojo::test::ApplicationTestBase {
+ public:
+ SQLTestBase();
+ ~SQLTestBase() override;
+
+ // Returns the path to the database.
+ base::FilePath db_path();
+
+ // Returns a connection to the database at db_path().
+ sql::Connection& db();
+
+ // Closes the current connection to the database and reopens it.
+ bool Reopen();
+
+ // Proxying method around base::PathExists.
+ bool GetPathExists(const base::FilePath& path);
+
+ // SQLite stores the database size in the header, and if the actual
+ // OS-derived size is smaller, the database is considered corrupt.
+ // [This case is actually a common form of corruption in the wild.]
+ // This helper sets the in-header size to one page larger than the
+ // actual file size. The resulting file will return SQLITE_CORRUPT
+ // for most operations unless PRAGMA writable_schema is turned ON.
+ //
+ // Returns false if any error occurs accessing the file.
+ bool CorruptSizeInHeaderOfPath(const base::FilePath& path);
+
+ // 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.
+ void WriteJunkToDatabase(bool truncate);
+
+ // Sets the database file size to 0.
+ void TruncateDatabase();
+
+ // Overridden from testing::Test:
+ void SetUp() override;
+ void TearDown() override;
+
+ protected:
+ filesystem::FileSystemPtr& files() { return files_; }
+
+ private:
+ filesystem::FileSystemPtr files_;
+
+ scoped_ptr<ScopedMojoFilesystemVFS> vfs_;
+ sql::Connection db_;
+
+ DISALLOW_COPY_AND_ASSIGN(SQLTestBase);
+};
+
+} // namespace sql
+
+#endif // SQL_MOJO_SQL_TEST_BASE_H_

Powered by Google App Engine
This is Rietveld 408576698