Skip to content

Commit

Permalink
sql: Add feature test for default values on boolean columns in SQLite.
Browse files Browse the repository at this point in the history
The feature is used by //components/webdata. This test will help make
sure the feature keeps working as we upgrade SQLite.

Bug: 829893
Change-Id: Ie94439e5abd2cad4e0e15bad92ec3af462850b4c
Reviewed-on: https://chromium-review.googlesource.com/1015206
Reviewed-by: Chris Mumford <cmumford@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552419}
  • Loading branch information
pwnall authored and Commit Bot committed Apr 20, 2018
1 parent d42e135 commit bc7ab06
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sql/sqlite_features_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,34 @@ TEST_F(SQLiteFeaturesTest, ForeignKeySupport) {
EXPECT_EQ("", ExecuteWithResult(&db(), kSelectChildren));
}

// Ensure that our SQLite version supports booleans.
TEST_F(SQLiteFeaturesTest, BooleanSupport) {
ASSERT_TRUE(
db().Execute("CREATE TABLE flags ("
" id INTEGER PRIMARY KEY,"
" true_flag BOOL NOT NULL DEFAULT TRUE,"
" false_flag BOOL NOT NULL DEFAULT FALSE)"));
ASSERT_TRUE(db().Execute(
"ALTER TABLE flags ADD COLUMN true_flag2 BOOL NOT NULL DEFAULT TRUE"));
ASSERT_TRUE(db().Execute(
"ALTER TABLE flags ADD COLUMN false_flag2 BOOL NOT NULL DEFAULT FALSE"));
ASSERT_TRUE(db().Execute("INSERT INTO flags (id) VALUES (1)"));

sql::Statement s(db().GetUniqueStatement(
"SELECT true_flag, false_flag, true_flag2, false_flag2"
" FROM flags WHERE id=1;"));
ASSERT_TRUE(s.Step());

// TODO(pwnall): Enable this check after upgrading to SQLite 3.23.
// EXPECT_TRUE(s.ColumnBool(0)) << " default TRUE at table creation time";
EXPECT_TRUE(!s.ColumnBool(1)) << " default FALSE at table creation time";

// TODO(pwnall): Enable this check after upgrading to SQLite 3.23.
// EXPECT_TRUE(s.ColumnBool(2))
// << " default TRUE added by altering the table";
EXPECT_TRUE(!s.ColumnBool(3)) << " default FALSE added by altering the table";
}

#if defined(OS_FUCHSIA)
// If the platform cannot support SQLite mmap'ed I/O, make sure SQLite isn't
// offering to support it.
Expand Down

0 comments on commit bc7ab06

Please sign in to comment.