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.
5 #include "sql/test/sql_test_base.h"
7 #include "base/files/file_util.h"
8 #include "sql/test/test_helpers.h"
12 SQLTestBase::SQLTestBase() {
15 SQLTestBase::~SQLTestBase() {
18 base::FilePath
SQLTestBase::db_path() {
19 return temp_dir_
.path().AppendASCII("SQLTest.db");
22 sql::Connection
& SQLTestBase::db() {
26 bool SQLTestBase::Reopen() {
28 return db_
.Open(db_path());
31 bool SQLTestBase::GetPathExists(const base::FilePath
& path
) {
32 return base::PathExists(path
);
35 bool SQLTestBase::CorruptSizeInHeaderOfDB() {
36 return sql::test::CorruptSizeInHeader(db_path());
39 void SQLTestBase::WriteJunkToDatabase(WriteJunkType type
) {
40 base::ScopedFILE
file(base::OpenFile(
42 type
== TYPE_OVERWRITE_AND_TRUNCATE
? "wb" : "rb+"));
43 ASSERT_TRUE(file
.get() != NULL
);
44 ASSERT_EQ(0, fseek(file
.get(), 0, SEEK_SET
));
46 const char* kJunk
= "Now is the winter of our discontent.";
47 fputs(kJunk
, file
.get());
50 void SQLTestBase::TruncateDatabase() {
51 base::ScopedFILE
file(base::OpenFile(db_path(), "rb+"));
52 ASSERT_TRUE(file
.get() != NULL
);
53 ASSERT_EQ(0, fseek(file
.get(), 0, SEEK_SET
));
54 ASSERT_TRUE(base::TruncateFile(file
.get()));
57 void SQLTestBase::SetUp() {
58 ASSERT_TRUE(temp_dir_
.CreateUniqueTempDir());
59 ASSERT_TRUE(db_
.Open(db_path()));
62 void SQLTestBase::TearDown() {