Index: sql/connection_unittest.cc |
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc |
index e8f454fa13493ada1ebf7de0cc7f09ba4a1b393a..2bac3fdf92c25fc98439a27d1bfa39749369aa93 100644 |
--- a/sql/connection_unittest.cc |
+++ b/sql/connection_unittest.cc |
@@ -279,6 +279,55 @@ TEST_F(SQLConnectionTest, RazeLocked) { |
ASSERT_TRUE(db().Raze()); |
} |
+TEST_F(SQLConnectionTest, RazeAndClose) { |
+ const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; |
+ const char* kPopulateSql = "INSERT INTO foo (value) VALUES (12)"; |
+ |
+ // Test that RazeAndClose() closes the database, and that the |
+ // database is empty when re-opened. |
+ ASSERT_TRUE(db().Execute(kCreateSql)); |
+ ASSERT_TRUE(db().Execute(kPopulateSql)); |
+ ASSERT_TRUE(db().RazeAndClose()); |
+ ASSERT_FALSE(db().is_open()); |
+ ASSERT_TRUE(db().Open(db_path())); |
+ { |
+ sql::Statement s(db().GetUniqueStatement("SELECT * FROM sqlite_master")); |
+ ASSERT_FALSE(s.Step()); |
+ } |
+ |
+ // Test that RazeAndClose() can break transactions. |
+ ASSERT_TRUE(db().Execute(kCreateSql)); |
+ ASSERT_TRUE(db().Execute(kPopulateSql)); |
+ ASSERT_TRUE(db().BeginTransaction()); |
+ ASSERT_TRUE(db().RazeAndClose()); |
+ ASSERT_FALSE(db().is_open()); |
+ ASSERT_FALSE(db().CommitTransaction()); |
+ ASSERT_TRUE(db().Open(db_path())); |
+ { |
+ sql::Statement s(db().GetUniqueStatement("SELECT * FROM sqlite_master")); |
+ ASSERT_FALSE(s.Step()); |
+ } |
+ |
+ // Test that statements start failed after RazeAndClose(). |
+ ASSERT_TRUE(db().Execute(kCreateSql)); |
+ ASSERT_TRUE(db().Execute(kPopulateSql)); |
+ { |
+ sql::Statement s(db().GetUniqueStatement("SELECT * FROM foo")); |
+ ASSERT_TRUE(db().RazeAndClose()); |
+ ASSERT_FALSE(s.Run()); |
+ } |
+ ASSERT_FALSE(db().is_open()); |
+ ASSERT_TRUE(db().Open(db_path())); |
+ { |
+ sql::Statement s(db().GetUniqueStatement("SELECT * FROM sqlite_master")); |
+ ASSERT_FALSE(s.Step()); |
+ } |
+} |
+ |
+// TODO(shess): Spin up a background thread to hold other_db, to more |
+// closely match real life. That would also allow testing |
+// RazeWithTimeout(). |
+ |
#if defined(OS_ANDROID) |
TEST_F(SQLConnectionTest, SetTempDirForSQL) { |
@@ -291,7 +340,3 @@ TEST_F(SQLConnectionTest, SetTempDirForSQL) { |
ASSERT_TRUE(meta_table.Init(&db(), 4, 4)); |
} |
#endif |
- |
-// TODO(shess): Spin up a background thread to hold other_db, to more |
-// closely match real life. That would also allow testing |
-// RazeWithTimeout(). |