OLD | NEW |
(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 #include "sql/test/sql_test_base.h" |
| 6 |
| 7 #include "base/files/file_util.h" |
| 8 #include "sql/test/test_helpers.h" |
| 9 |
| 10 namespace sql { |
| 11 |
| 12 SQLTestBase::SQLTestBase() { |
| 13 } |
| 14 |
| 15 SQLTestBase::~SQLTestBase() { |
| 16 } |
| 17 |
| 18 base::FilePath SQLTestBase::db_path() { |
| 19 return temp_dir_.path().AppendASCII("SQLTest.db"); |
| 20 } |
| 21 |
| 22 sql::Connection& SQLTestBase::db() { |
| 23 return db_; |
| 24 } |
| 25 |
| 26 bool SQLTestBase::Reopen() { |
| 27 db_.Close(); |
| 28 return db_.Open(db_path()); |
| 29 } |
| 30 |
| 31 bool SQLTestBase::GetPathExists(const base::FilePath& path) { |
| 32 return base::PathExists(path); |
| 33 } |
| 34 |
| 35 bool SQLTestBase::CorruptSizeInHeaderOfPath(const base::FilePath& db_path) { |
| 36 return sql::test::CorruptSizeInHeader(db_path); |
| 37 } |
| 38 |
| 39 void SQLTestBase::WriteJunkToDatabase(WriteJunkType type) { |
| 40 base::ScopedFILE file(base::OpenFile( |
| 41 db_path(), |
| 42 type == TYPE_TRUNCATE_AND_CREATE ? "wb" : "rb+")); |
| 43 ASSERT_TRUE(file.get() != NULL); |
| 44 ASSERT_EQ(0, fseek(file.get(), 0, SEEK_SET)); |
| 45 |
| 46 const char* kJunk = "Now is the winter of our discontent."; |
| 47 fputs(kJunk, file.get()); |
| 48 } |
| 49 |
| 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())); |
| 55 } |
| 56 |
| 57 void SQLTestBase::SetUp() { |
| 58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 59 ASSERT_TRUE(db_.Open(db_path())); |
| 60 } |
| 61 |
| 62 void SQLTestBase::TearDown() { |
| 63 db_.Close(); |
| 64 } |
| 65 |
| 66 } // namespace sql |
OLD | NEW |