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

Unified Diff: sql/connection_unittest.cc

Issue 1069313004: [sql] Change DoesStuffExist() to work with ScopedErrorIgnorer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« sql/connection.cc ('K') | « sql/connection.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection_unittest.cc
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc
index 07c9fa7c732c0714e4eb07a5799f0946ed7a1076..3cb2e370fb4a21102c6c16cb18986cdfb5207b9d 100644
--- a/sql/connection_unittest.cc
+++ b/sql/connection_unittest.cc
@@ -176,10 +176,9 @@ TEST_F(SQLConnectionTest, DoesStuffExist) {
// Test DoesTableExist.
EXPECT_FALSE(db().DoesTableExist("foo"));
ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
+ ASSERT_TRUE(db().Execute("CREATE INDEX foo_a ON foo (a)"));
EXPECT_TRUE(db().DoesTableExist("foo"));
-
- // Should be case sensitive.
- EXPECT_FALSE(db().DoesTableExist("FOO"));
+ EXPECT_TRUE(db().DoesIndexExist("foo_a"));
// Test DoesColumnExist.
EXPECT_FALSE(db().DoesColumnExist("foo", "bar"));
@@ -187,6 +186,10 @@ TEST_F(SQLConnectionTest, DoesStuffExist) {
// Testing for a column on a nonexistent table.
EXPECT_FALSE(db().DoesColumnExist("bar", "b"));
+
+ // Names are not case sensitive.
+ EXPECT_TRUE(db().DoesTableExist("FOO"));
+ EXPECT_TRUE(db().DoesColumnExist("FOO", "A"));
}
TEST_F(SQLConnectionTest, GetLastInsertRowId) {
@@ -221,10 +224,36 @@ TEST_F(SQLConnectionTest, ScopedIgnoreError) {
ASSERT_TRUE(db().Execute(kCreateSql));
ASSERT_TRUE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CONSTRAINT);
- ASSERT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ {
+ sql::ScopedErrorIgnorer ignore_errors;
+ ignore_errors.IgnoreError(SQLITE_CONSTRAINT);
+ ASSERT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ }
+}
+
+// Test that clients of GetUntrackedStatement() can test corruption-handling
+// with ScopedErrorIgnorer.
+TEST_F(SQLConnectionTest, ScopedIgnoreUntracked) {
+ const char* kCreateSql = "CREATE TABLE foo (id INTEGER UNIQUE)";
+ ASSERT_TRUE(db().Execute(kCreateSql));
+ ASSERT_FALSE(db().DoesTableExist("bar"));
+ ASSERT_TRUE(db().DoesTableExist("foo"));
+ ASSERT_TRUE(db().DoesColumnExist("foo", "id"));
+ db().Close();
+
+ // Corrupt the database so that nothing works, including PRAGMAs.
+ ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path()));
+
+ {
+ sql::ScopedErrorIgnorer ignore_errors;
+ ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ ASSERT_TRUE(db().Open(db_path()));
+ ASSERT_FALSE(db().DoesTableExist("bar"));
+ ASSERT_FALSE(db().DoesTableExist("foo"));
+ ASSERT_FALSE(db().DoesColumnExist("foo", "id"));
+ ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ }
}
TEST_F(SQLConnectionTest, ErrorCallback) {
« sql/connection.cc ('K') | « sql/connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698