OLD | NEW |
---|---|
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "sql/connection.h" | 9 #include "sql/connection.h" |
10 #include "sql/meta_table.h" | 10 #include "sql/meta_table.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 } | 81 } |
82 ~ScopedUmaskSetter() { umask(old_umask_); } | 82 ~ScopedUmaskSetter() { umask(old_umask_); } |
83 private: | 83 private: |
84 mode_t old_umask_; | 84 mode_t old_umask_; |
85 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedUmaskSetter); | 85 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedUmaskSetter); |
86 }; | 86 }; |
87 #endif | 87 #endif |
88 | 88 |
89 class SQLConnectionTest : public testing::Test { | 89 class SQLConnectionTest : public testing::Test { |
90 public: | 90 public: |
91 SQLConnectionTest() {} | |
92 | |
93 virtual void SetUp() { | 91 virtual void SetUp() { |
94 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 92 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
95 ASSERT_TRUE(db_.Open(db_path())); | 93 db_path_ = temp_dir_.path().AppendASCII("SQLConnectionTest.db"); |
94 ASSERT_TRUE(db_.Open(db_path_)); | |
96 } | 95 } |
97 | 96 |
98 virtual void TearDown() { | 97 virtual void TearDown() { |
99 db_.Close(); | 98 db_.Close(); |
100 } | 99 } |
101 | 100 |
102 sql::Connection& db() { return db_; } | 101 sql::Connection& db() { return db_; } |
103 | 102 const base::FilePath& db_path() { return db_path_; } |
Greg Billock
2013/09/06 16:02:10
Here it gets used in tests. So having both in the
| |
104 base::FilePath db_path() { | |
105 return temp_dir_.path().AppendASCII("SQLConnectionTest.db"); | |
106 } | |
107 | 103 |
108 // Handle errors by blowing away the database. | 104 // Handle errors by blowing away the database. |
109 void RazeErrorCallback(int expected_error, int error, sql::Statement* stmt) { | 105 void RazeErrorCallback(int expected_error, int error, sql::Statement* stmt) { |
110 EXPECT_EQ(expected_error, error); | 106 EXPECT_EQ(expected_error, error); |
111 db_.RazeAndClose(); | 107 db_.RazeAndClose(); |
112 } | 108 } |
113 | 109 |
114 private: | 110 private: |
111 sql::Connection db_; | |
112 base::FilePath db_path_; | |
115 base::ScopedTempDir temp_dir_; | 113 base::ScopedTempDir temp_dir_; |
116 sql::Connection db_; | |
117 }; | 114 }; |
118 | 115 |
119 TEST_F(SQLConnectionTest, Execute) { | 116 TEST_F(SQLConnectionTest, Execute) { |
120 // Valid statement should return true. | 117 // Valid statement should return true. |
121 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); | 118 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)")); |
122 EXPECT_EQ(SQLITE_OK, db().GetErrorCode()); | 119 EXPECT_EQ(SQLITE_OK, db().GetErrorCode()); |
123 | 120 |
124 // Invalid statement should fail. | 121 // Invalid statement should fail. |
125 ASSERT_EQ(SQLITE_ERROR, | 122 ASSERT_EQ(SQLITE_ERROR, |
126 db().ExecuteAndReturnErrorCode("CREATE TAB foo (a, b")); | 123 db().ExecuteAndReturnErrorCode("CREATE TAB foo (a, b")); |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 } | 833 } |
837 | 834 |
838 // Detach succeeds outside of a transaction. | 835 // Detach succeeds outside of a transaction. |
839 db().RollbackTransaction(); | 836 db().RollbackTransaction(); |
840 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint)); | 837 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint)); |
841 | 838 |
842 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar")); | 839 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar")); |
843 } | 840 } |
844 | 841 |
845 } // namespace | 842 } // namespace |
OLD | NEW |