0
Files
src/sql/test/sql_test_base.cc
erg 102ceb4133 mandoline filesystem: add a sqlite3 vfs to proxy filesystem usage.
This adds a //sql/mojo library which can be linked into preexisting
sqlite3 code which adds a new VFS which transparently proxies filesystem
usage to the mojo:filesystem application.

We create a new sql_apptests.mojo target, which currently has all the
sql connection_unittests.cc (minus 2 hard ones), all statement and
transaction unit tests and refactor the sql testing stuff so that we
have two implementations of an SQLTestBase class: one that uses files
raw and one that proxies to the filesystem process.

Notably, this patch does not implement file locking, which will have to
be implemented before we can safely use this, but will be a large enough
patch in and of itself that I'm punting on it for this patch.

BUG=493311

Review URL: https://codereview.chromium.org/1176653002

Cr-Commit-Position: refs/heads/master@{#335415}
2015-06-20 01:38:55 +00:00

67 lines
1.5 KiB
C++

// 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.
#include "sql/test/sql_test_base.h"
#include "base/files/file_util.h"
#include "sql/test/test_helpers.h"
namespace sql {
SQLTestBase::SQLTestBase() {
}
SQLTestBase::~SQLTestBase() {
}
base::FilePath SQLTestBase::db_path() {
return temp_dir_.path().AppendASCII("SQLTest.db");
}
sql::Connection& SQLTestBase::db() {
return db_;
}
bool SQLTestBase::Reopen() {
db_.Close();
return db_.Open(db_path());
}
bool SQLTestBase::GetPathExists(const base::FilePath& path) {
return base::PathExists(path);
}
bool SQLTestBase::CorruptSizeInHeaderOfDB() {
return sql::test::CorruptSizeInHeader(db_path());
}
void SQLTestBase::WriteJunkToDatabase(WriteJunkType type) {
base::ScopedFILE file(base::OpenFile(
db_path(),
type == TYPE_OVERWRITE_AND_TRUNCATE ? "wb" : "rb+"));
ASSERT_TRUE(file.get() != NULL);
ASSERT_EQ(0, fseek(file.get(), 0, SEEK_SET));
const char* kJunk = "Now is the winter of our discontent.";
fputs(kJunk, file.get());
}
void SQLTestBase::TruncateDatabase() {
base::ScopedFILE file(base::OpenFile(db_path(), "rb+"));
ASSERT_TRUE(file.get() != NULL);
ASSERT_EQ(0, fseek(file.get(), 0, SEEK_SET));
ASSERT_TRUE(base::TruncateFile(file.get()));
}
void SQLTestBase::SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(db_.Open(db_path()));
}
void SQLTestBase::TearDown() {
db_.Close();
}
} // namespace sql