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

Side by Side Diff: sql/sqlite_features_unittest.cc

Issue 10542096: Avoid leaking any files from SQLiteFeaturesTest. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 unified diff | Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/file_path.h"
8 #include "base/file_util.h" 7 #include "base/file_util.h"
9 #include "base/path_service.h" 8 #include "base/scoped_temp_dir.h"
10 #include "sql/connection.h" 9 #include "sql/connection.h"
11 #include "sql/statement.h" 10 #include "sql/statement.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/sqlite/sqlite3.h" 12 #include "third_party/sqlite/sqlite3.h"
14 13
15 // Test that certain features are/are-not enabled in our SQLite. 14 // Test that certain features are/are-not enabled in our SQLite.
16 15
17 namespace { 16 namespace {
18 17
19 18
(...skipping 24 matching lines...) Expand all
44 private: 43 private:
45 int error_; 44 int error_;
46 std::string sql_text_; 45 std::string sql_text_;
47 }; 46 };
48 47
49 class SQLiteFeaturesTest : public testing::Test { 48 class SQLiteFeaturesTest : public testing::Test {
50 public: 49 public:
51 SQLiteFeaturesTest() : error_handler_(new StatementErrorHandler) {} 50 SQLiteFeaturesTest() : error_handler_(new StatementErrorHandler) {}
52 51
53 void SetUp() { 52 void SetUp() {
54 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_)); 53 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
55 path_ = path_.AppendASCII("SQLStatementTest.db"); 54 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db")));
56 file_util::Delete(path_, false); 55
57 ASSERT_TRUE(db_.Open(path_));
58 // The |error_handler_| will be called if any sqlite statement operation 56 // The |error_handler_| will be called if any sqlite statement operation
59 // returns an error code. 57 // returns an error code.
60 db_.set_error_delegate(error_handler_); 58 db_.set_error_delegate(error_handler_);
61 } 59 }
62 60
63 void TearDown() { 61 void TearDown() {
64 // If any error happened the original sql statement can be found in 62 // If any error happened the original sql statement can be found in
65 // error_handler_->sql_statement(). 63 // error_handler_->sql_statement().
66 EXPECT_EQ(SQLITE_OK, error_handler_->error()); 64 EXPECT_EQ(SQLITE_OK, error_handler_->error());
67 db_.Close(); 65 db_.Close();
68 // If this fails something is going on with cleanup and later tests may
69 // fail, so we want to identify problems right away.
70 ASSERT_TRUE(file_util::Delete(path_, false));
71 } 66 }
72 67
73 sql::Connection& db() { return db_; } 68 sql::Connection& db() { return db_; }
74 69
75 int sqlite_error() const { return error_handler_->error(); } 70 int sqlite_error() const { return error_handler_->error(); }
76 void reset_error() const { error_handler_->reset_error(); } 71 void reset_error() const { error_handler_->reset_error(); }
77 72
78 private: 73 private:
79 FilePath path_; 74 ScopedTempDir temp_dir_;
80 sql::Connection db_; 75 sql::Connection db_;
81 scoped_refptr<StatementErrorHandler> error_handler_; 76 scoped_refptr<StatementErrorHandler> error_handler_;
82 }; 77 };
83 78
84 // Do not include fts1 support, it is not useful, and nobody is 79 // Do not include fts1 support, it is not useful, and nobody is
85 // looking at it. 80 // looking at it.
86 TEST_F(SQLiteFeaturesTest, NoFTS1) { 81 TEST_F(SQLiteFeaturesTest, NoFTS1) {
87 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode( 82 ASSERT_EQ(SQLITE_ERROR, db().ExecuteAndReturnErrorCode(
88 "CREATE VIRTUAL TABLE foo USING fts1(x)")); 83 "CREATE VIRTUAL TABLE foo USING fts1(x)"));
89 } 84 }
90 85
91 // fts2 is used for older history files, so we're signed on for 86 // fts2 is used for older history files, so we're signed on for
92 // keeping our version up-to-date. 87 // keeping our version up-to-date.
93 // TODO(shess): Think up a crazy way to get out from having to support 88 // TODO(shess): Think up a crazy way to get out from having to support
94 // this forever. 89 // this forever.
95 TEST_F(SQLiteFeaturesTest, FTS2) { 90 TEST_F(SQLiteFeaturesTest, FTS2) {
96 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)")); 91 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts2(x)"));
97 } 92 }
98 93
99 // fts3 is used for current history files, and also for WebDatabase. 94 // fts3 is used for current history files, and also for WebDatabase.
100 TEST_F(SQLiteFeaturesTest, FTS3) { 95 TEST_F(SQLiteFeaturesTest, FTS3) {
101 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)")); 96 ASSERT_TRUE(db().Execute("CREATE VIRTUAL TABLE foo USING fts3(x)"));
102 } 97 }
103 98
104 } // namespace 99 } // namespace
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698