diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 22:18:10 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 22:18:10 +0000 |
commit | 4350e321e41d0faa025ac516aad6365bc8e9a83f (patch) | |
tree | 23d66544bf4dc0f62a20820f66ad2264b2323eee /sql/connection_unittest.cc | |
parent | 90392f8e3110e58c0367c4d87caa7f33709bff6c (diff) | |
download | chromium_src-4350e321e41d0faa025ac516aad6365bc8e9a83f.zip chromium_src-4350e321e41d0faa025ac516aad6365bc8e9a83f.tar.gz chromium_src-4350e321e41d0faa025ac516aad6365bc8e9a83f.tar.bz2 |
[sql] Framework for allowing tests to handle errors.
sql/ throws FATAL whenever it sees inappropriate calls, which makes
production code to handle errors hard to test. ScopedErrorIgnorer
provides a way for tests to signal that specific errors are expected
and will be handled.
As a first pass, code up some additional tests for some Raze() edge
cases, and modify things to pass those tests.
BUG=159490
Review URL: https://chromiumcodereview.appspot.com/16664005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/connection_unittest.cc')
-rw-r--r-- | sql/connection_unittest.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sql/connection_unittest.cc b/sql/connection_unittest.cc index 2aaeb27..b43e83c 100644 --- a/sql/connection_unittest.cc +++ b/sql/connection_unittest.cc @@ -8,6 +8,7 @@ #include "sql/connection.h" #include "sql/meta_table.h" #include "sql/statement.h" +#include "sql/test/scoped_error_ignorer.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/sqlite/sqlite3.h" @@ -136,6 +137,19 @@ TEST_F(SQLConnectionTest, Rollback) { EXPECT_TRUE(db().BeginTransaction()); } +// Test the scoped error ignorer by attempting to insert a duplicate +// value into an index. +TEST_F(SQLConnectionTest, ScopedIgnoreError) { + const char* kCreateSql = "CREATE TABLE foo (id INTEGER UNIQUE)"; + 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()); +} + // Test that sql::Connection::Raze() results in a database without the // tables from the original database. TEST_F(SQLConnectionTest, Raze) { |