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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
7 #include "sql/connection.h" | 7 #include "sql/connection.h" |
8 #include "sql/statement.h" | 8 #include "sql/statement.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/sqlite/sqlite3.h" | 10 #include "third_party/sqlite/sqlite3.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 db().set_page_size(kPageSize); | 188 db().set_page_size(kPageSize); |
189 ASSERT_TRUE(db().Open(db_path())); | 189 ASSERT_TRUE(db().Open(db_path())); |
190 | 190 |
191 // page_size should match the indicated value. | 191 // page_size should match the indicated value. |
192 sql::Statement s(db().GetUniqueStatement("PRAGMA page_size")); | 192 sql::Statement s(db().GetUniqueStatement("PRAGMA page_size")); |
193 ASSERT_TRUE(s.Step()); | 193 ASSERT_TRUE(s.Step()); |
194 ASSERT_EQ(kPageSize, s.ColumnInt(0)); | 194 ASSERT_EQ(kPageSize, s.ColumnInt(0)); |
195 | 195 |
196 // After raze, page_size should still match the indicated value. | 196 // After raze, page_size should still match the indicated value. |
197 ASSERT_TRUE(db().Raze()); | 197 ASSERT_TRUE(db().Raze()); |
198 s.Reset(); | 198 s.Reset(true); |
199 ASSERT_TRUE(s.Step()); | 199 ASSERT_TRUE(s.Step()); |
200 ASSERT_EQ(kPageSize, s.ColumnInt(0)); | 200 ASSERT_EQ(kPageSize, s.ColumnInt(0)); |
201 } | 201 } |
202 | 202 |
203 // Test that Raze() results are seen in other connections. | 203 // Test that Raze() results are seen in other connections. |
204 TEST_F(SQLConnectionTest, RazeMultiple) { | 204 TEST_F(SQLConnectionTest, RazeMultiple) { |
205 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; | 205 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; |
206 ASSERT_TRUE(db().Execute(kCreateSql)); | 206 ASSERT_TRUE(db().Execute(kCreateSql)); |
207 | 207 |
208 sql::Connection other_db; | 208 sql::Connection other_db; |
209 ASSERT_TRUE(other_db.Open(db_path())); | 209 ASSERT_TRUE(other_db.Open(db_path())); |
210 | 210 |
211 // Check that the second connection sees the table. | 211 // Check that the second connection sees the table. |
212 const char *kTablesQuery = "SELECT COUNT(*) FROM sqlite_master"; | 212 const char *kTablesQuery = "SELECT COUNT(*) FROM sqlite_master"; |
213 sql::Statement s(other_db.GetUniqueStatement(kTablesQuery)); | 213 sql::Statement s(other_db.GetUniqueStatement(kTablesQuery)); |
214 ASSERT_TRUE(s.Step()); | 214 ASSERT_TRUE(s.Step()); |
215 ASSERT_EQ(1, s.ColumnInt(0)); | 215 ASSERT_EQ(1, s.ColumnInt(0)); |
216 ASSERT_FALSE(s.Step()); // Releases the shared lock. | 216 ASSERT_FALSE(s.Step()); // Releases the shared lock. |
217 | 217 |
218 ASSERT_TRUE(db().Raze()); | 218 ASSERT_TRUE(db().Raze()); |
219 | 219 |
220 // The second connection sees the updated database. | 220 // The second connection sees the updated database. |
221 s.Reset(); | 221 s.Reset(true); |
222 ASSERT_TRUE(s.Step()); | 222 ASSERT_TRUE(s.Step()); |
223 ASSERT_EQ(0, s.ColumnInt(0)); | 223 ASSERT_EQ(0, s.ColumnInt(0)); |
224 } | 224 } |
225 | 225 |
226 TEST_F(SQLConnectionTest, RazeLocked) { | 226 TEST_F(SQLConnectionTest, RazeLocked) { |
227 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; | 227 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; |
228 ASSERT_TRUE(db().Execute(kCreateSql)); | 228 ASSERT_TRUE(db().Execute(kCreateSql)); |
229 | 229 |
230 // Open a transaction and write some data in a second connection. | 230 // Open a transaction and write some data in a second connection. |
231 // This will acquire a PENDING or EXCLUSIVE transaction, which will | 231 // This will acquire a PENDING or EXCLUSIVE transaction, which will |
(...skipping 22 matching lines...) Expand all Loading... |
254 ASSERT_FALSE(db().Raze()); | 254 ASSERT_FALSE(db().Raze()); |
255 | 255 |
256 // Complete the statement unlocks the database. | 256 // Complete the statement unlocks the database. |
257 ASSERT_FALSE(s.Step()); | 257 ASSERT_FALSE(s.Step()); |
258 ASSERT_TRUE(db().Raze()); | 258 ASSERT_TRUE(db().Raze()); |
259 } | 259 } |
260 | 260 |
261 // TODO(shess): Spin up a background thread to hold other_db, to more | 261 // TODO(shess): Spin up a background thread to hold other_db, to more |
262 // closely match real life. That would also allow testing | 262 // closely match real life. That would also allow testing |
263 // RazeWithTimeout(). | 263 // RazeWithTimeout(). |
OLD | NEW |