Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / sql / test / sql_test_base.cc
blobbdd427fe7c105a0840bf43fb50c4d95573c4e58f
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"
10 namespace sql {
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() {
23 return db_;
26 bool SQLTestBase::Reopen() {
27 db_.Close();
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(
41 db_path(),
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() {
63 db_.Close();
66 } // namespace sql